mirror of
https://github.com/RevenueCat/purchases-ios
synced 2026-11-11 22:55:55 +05:45
* refactor: move rules engine into core SDK as internal Move the RulesEngineInternal sources and tests into the RevenueCat target under Sources/RulesEngine and Tests/UnitTests/RulesEngine. The moved symbols are marked internal so no new public API is exposed, and the standalone RulesEngineInternal target is removed from Package manifests, Tuist, the Xcode project, and CI. No usages yet. Co-authored-by: Cursor <cursoragent@cursor.com> * refactor: namespace rules engine types under RulesEngine Nest the generically-named rules engine types (Value, Evaluator, Operators and the per-category operator enums), the JS coercion helpers, and PrintLogger inside the RulesEngine enum so the subsystem exposes a single top-level symbol instead of polluting the RevenueCat module's internal namespace. RulesEngineLogger stays top-level (already prefixed). Production cross-references resolve via enclosing scope; tests use local typealiases or explicit RulesEngine. qualification. Co-authored-by: Cursor <cursoragent@cursor.com> * Document why the rules engine owns its own logging abstraction Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Cursor <cursoragent@cursor.com>
62 lines
1.9 KiB
Swift
62 lines
1.9 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
|
|
//
|
|
// RulesEngine.swift
|
|
//
|
|
// Created by Antonio Pallares.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
/// Namespace for the RevenueCat rules engine.
|
|
enum RulesEngine {}
|
|
|
|
extension RulesEngine {
|
|
|
|
/// Per-task override used by tests and scoped diagnostic callers.
|
|
/// When `nil`, logging falls through to the module default.
|
|
@TaskLocal static var scopedLogger: RulesEngineLogger?
|
|
|
|
static var logger: RulesEngineLogger {
|
|
scopedLogger ?? loggerStorage.value
|
|
}
|
|
|
|
// The rules engine deliberately owns its own logging abstraction (`RulesEngineLogger`) instead
|
|
// of routing through the SDK-wide logger. This keeps it self-contained so it can be extracted
|
|
// back into a standalone module as mechanically as it was folded in. If we commit to it living
|
|
// in core long-term, consider bridging this to the SDK's logging system instead.
|
|
/// Replaces the module default logger. Intended to be called once during configure.
|
|
static func setLogger(_ logger: RulesEngineLogger) {
|
|
loggerStorage.value = logger
|
|
}
|
|
|
|
private static let loggerStorage = LoggerStorage()
|
|
}
|
|
|
|
/// Locked storage for the module default logger. A reference type so the enclosing
|
|
/// namespace's `static let loggerStorage` can be a stored property.
|
|
private final class LoggerStorage: @unchecked Sendable {
|
|
|
|
private let lock = NSLock()
|
|
private var current: RulesEngineLogger = RulesEngine.PrintLogger()
|
|
|
|
var value: RulesEngineLogger {
|
|
get {
|
|
lock.lock()
|
|
defer { lock.unlock() }
|
|
return current
|
|
}
|
|
set {
|
|
lock.lock()
|
|
defer { lock.unlock() }
|
|
current = newValue
|
|
}
|
|
}
|
|
}
|