Files
purchases-ios/RulesEngineInternal/RulesEngineInternal.swift
T
Antonio PallaresandCursor 0ff0e3dafe Merge branch 'pallares/rules-engine-enforce-internal-api' into pallares/json-logic-evaluator
Brings in:
- The `RulesEngine` → `RulesEngineInternal` module rename from #6787.
- The `no_leaking_rules_engine_internal_import` SwiftLint rule update from #6788.
- Plus the `main`-merge cascade carried by #6788.

Conflicts resolved:

- `RulesEngineInternal/RulesEngineInternal.swift`: kept this branch's
  `Rules.logger` / `LoggerStorage` storage, dropped the
  `@_spi(Internal)` marker on `public enum Rules` (since #6787 dropped
  those markers; the new SwiftLint rule replaces that gate).
- `RevenueCat.xcodeproj/project.pbxproj`: kept this branch's full file
  list (Evaluator, Logger, Value, RuleError, Operators/*, plus the new
  test files and helpers), then applied the producer-side rename to
  every `RulesEngine\b` / `RulesEngineTests\b` token (target name,
  group name, path, productName, bundle IDs `com.revenuecat.RulesEngineInternal[Tests]`,
  framework / xctest output names, and the `RulesEngine.swift` → `RulesEngineInternal.swift`
  file ref).

Other rename follow-ups in this branch's added files:

- `Tests/RulesEngineInternalTests/*.swift` (8 files) — every
  `[@_spi(Internal) ]@testable import RulesEngine` updated to
  `@testable import RulesEngineInternal`. The `@_spi(Internal)`
  attribute is no longer needed because the producer no longer uses
  SPI markers.
- `Projects/RulesEngineInternal/`, `RulesEngineInternal/`, and
  `Tests/RulesEngineInternalTests/` directories were moved
  automatically by git's directory-rename detection (15 file renames).

Left intentionally unchanged:

- `RulesEngineInternal/Logger.swift` — the development-only
  `PrintLogger` keeps its `[RulesEngine]` log prefix because that
  string identifies the subsystem (the rules engine) for log readers,
  not the producer-side module name. The injected production logger
  replaces this struct entirely once the engine is wired into the SDK,
  so the prefix is throwaway.
- `RulesEngineLogger` protocol name — internal type name within the
  module, not part of the import-site signal that motivated the
  module rename.
- The `Rules` namespace name — separate identifier from the module
  name, kept stable so call sites still write `Rules.something`.

Verified locally:
- `swift build --target RulesEngineInternal` ✔
- `swift test --filter RulesEngineInternalTests` ✔ — 75 tests passed
- `xcodebuild -scheme RulesEngineInternal -destination 'generic/platform=iOS' build` ✔
- `swiftlint --no-cache` ✔ — 0 violations across 1332 files
- `git ls-files | xargs perl -ne 'if (/\bRulesEngine\b/ && !/RulesEngineInternal/) { ... }'` returns only the `[RulesEngine]` log prefix mentioned above.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-21 17:51:26 +02:00

52 lines
1.2 KiB
Swift

//
// Copyright RevenueCat Inc. All Rights Reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// RulesEngineInternal.swift
//
// Created by Antonio Pallares.
//
import Foundation
/// Namespace for the RevenueCat rules engine.
public enum Rules {}
extension Rules {
static var logger: RulesEngineLogger {
get { loggerStorage.value }
set { loggerStorage.value = newValue }
}
private static let loggerStorage = LoggerStorage()
}
/// Locked storage for `Rules.logger`. A reference type so the enclosing
/// namespace's `static let loggerStorage` can be a stored property
/// (Swift forbids stored properties on enums, but `static let` of a
/// class instance is fine).
private final class LoggerStorage {
private let lock = NSLock()
private var current: RulesEngineLogger = PrintLogger()
var value: RulesEngineLogger {
get {
lock.lock()
defer { lock.unlock() }
return current
}
set {
lock.lock()
defer { lock.unlock() }
current = newValue
}
}
}