From 4838dfdd91f142f06aa5d2d2402505fd61df672d Mon Sep 17 00:00:00 2001 From: Dariusz Rybicki <dariusz@elixxir.io> Date: Thu, 21 Jul 2022 18:59:07 +0100 Subject: [PATCH] Add SetLogLevel functor --- .../Legacy/LogLevelConfigurator.swift | 31 ------------------- .../{Legacy => }/LogLevel.swift | 0 Sources/ElixxirDAppsSDK/SetLogLevel.swift | 27 ++++++++++++++++ 3 files changed, 27 insertions(+), 31 deletions(-) delete mode 100644 Sources/ElixxirDAppsSDK/Legacy/LogLevelConfigurator.swift rename Sources/ElixxirDAppsSDK/{Legacy => }/LogLevel.swift (100%) create mode 100644 Sources/ElixxirDAppsSDK/SetLogLevel.swift diff --git a/Sources/ElixxirDAppsSDK/Legacy/LogLevelConfigurator.swift b/Sources/ElixxirDAppsSDK/Legacy/LogLevelConfigurator.swift deleted file mode 100644 index 6137fc83..00000000 --- a/Sources/ElixxirDAppsSDK/Legacy/LogLevelConfigurator.swift +++ /dev/null @@ -1,31 +0,0 @@ -import Bindings - -public struct LogLevelConfigurator { - public var set: (LogLevel) throws -> Void - - public func callAsFunction(logLevel: LogLevel) throws { - try set(logLevel) - } -} - -extension LogLevelConfigurator { - public static let live = LogLevelConfigurator { logLevel in - var error: NSError? - let result = BindingsLogLevel(logLevel.rawValue, &error) - if let error = error { - throw error - } - if !result { - fatalError("BindingsLogLevel returned `false` without providing error") - } - } -} - -#if DEBUG -extension LogLevelConfigurator { - public static let failing = LogLevelConfigurator { _ in - struct NotImplemented: Error {} - throw NotImplemented() - } -} -#endif diff --git a/Sources/ElixxirDAppsSDK/Legacy/LogLevel.swift b/Sources/ElixxirDAppsSDK/LogLevel.swift similarity index 100% rename from Sources/ElixxirDAppsSDK/Legacy/LogLevel.swift rename to Sources/ElixxirDAppsSDK/LogLevel.swift diff --git a/Sources/ElixxirDAppsSDK/SetLogLevel.swift b/Sources/ElixxirDAppsSDK/SetLogLevel.swift new file mode 100644 index 00000000..487bfd8e --- /dev/null +++ b/Sources/ElixxirDAppsSDK/SetLogLevel.swift @@ -0,0 +1,27 @@ +import Bindings +import XCTestDynamicOverlay + +public struct SetLogLevel { + public var run: (LogLevel) throws -> Bool + + public func callAsFunction(_ logLevel: LogLevel) throws -> Bool { + try run(logLevel) + } +} + +extension SetLogLevel { + public static let live = SetLogLevel { logLevel in + var error: NSError? + let result = BindingsLogLevel(logLevel.rawValue, &error) + if let error = error { + throw error + } + return result + } +} + +extension SetLogLevel { + public static let unimplemented = SetLogLevel( + run: XCTUnimplemented("\(Self.self)") + ) +} -- GitLab