From f85474999c93b774cf39d39f6983c4a6ba8588ee Mon Sep 17 00:00:00 2001 From: Dariusz Rybicki <dariusz@elixxir.io> Date: Fri, 22 Jul 2022 12:39:45 +0100 Subject: [PATCH] Add ConnectionGetId functor --- Sources/ElixxirDAppsSDK/Connection.swift | 14 ++++++--- Sources/ElixxirDAppsSDK/ConnectionGetId.swift | 26 ++++++++++++++++ .../Legacy/ConnectionIdProvider.swift | 31 ------------------- 3 files changed, 36 insertions(+), 35 deletions(-) create mode 100644 Sources/ElixxirDAppsSDK/ConnectionGetId.swift delete mode 100644 Sources/ElixxirDAppsSDK/Legacy/ConnectionIdProvider.swift diff --git a/Sources/ElixxirDAppsSDK/Connection.swift b/Sources/ElixxirDAppsSDK/Connection.swift index cd44343a..c2e269ee 100644 --- a/Sources/ElixxirDAppsSDK/Connection.swift +++ b/Sources/ElixxirDAppsSDK/Connection.swift @@ -1,19 +1,25 @@ import Bindings public struct Connection { - // TODO: + public var getId: ConnectionGetId } extension Connection { public static func live(_ bindingsConnection: BindingsConnection) -> Connection { - Connection() + Connection( + getId: .live(bindingsConnection) + ) } public static func live(_ bindingsConnection: BindingsAuthenticatedConnection) -> Connection { - Connection() + Connection( + getId: .live(bindingsConnection) + ) } } extension Connection { - public static let unimplemented = Connection() + public static let unimplemented = Connection( + getId: .unimplemented + ) } diff --git a/Sources/ElixxirDAppsSDK/ConnectionGetId.swift b/Sources/ElixxirDAppsSDK/ConnectionGetId.swift new file mode 100644 index 00000000..cc976212 --- /dev/null +++ b/Sources/ElixxirDAppsSDK/ConnectionGetId.swift @@ -0,0 +1,26 @@ +import Bindings +import XCTestDynamicOverlay + +public struct ConnectionGetId { + public var run: () -> Int + + public func callAsFunction() -> Int { + run() + } +} + +extension ConnectionGetId { + public static func live(_ bindingsConnection: BindingsConnection) -> ConnectionGetId { + ConnectionGetId(run: bindingsConnection.getId) + } + + public static func live(_ bindingsConnection: BindingsAuthenticatedConnection) -> ConnectionGetId { + ConnectionGetId(run: bindingsConnection.getId) + } +} + +extension ConnectionGetId { + public static let unimplemented = ConnectionGetId( + run: XCTUnimplemented("\(Self.self)") + ) +} diff --git a/Sources/ElixxirDAppsSDK/Legacy/ConnectionIdProvider.swift b/Sources/ElixxirDAppsSDK/Legacy/ConnectionIdProvider.swift deleted file mode 100644 index 3261dfd4..00000000 --- a/Sources/ElixxirDAppsSDK/Legacy/ConnectionIdProvider.swift +++ /dev/null @@ -1,31 +0,0 @@ -import Bindings - -public struct ConnectionIdProvider { - public var get: () -> Int - - public func callAsFunction() -> Int { - get() - } -} - -extension ConnectionIdProvider { - public static func live( - bindingsConnection: BindingsConnection - ) -> ConnectionIdProvider { - ConnectionIdProvider(get: bindingsConnection.getId) - } - - public static func live( - bindingsAuthenticatedConnection: BindingsAuthenticatedConnection - ) -> ConnectionIdProvider { - ConnectionIdProvider(get: bindingsAuthenticatedConnection.getId) - } -} - -#if DEBUG -extension ConnectionIdProvider { - public static let failing = ConnectionIdProvider { - fatalError("Not implemented") - } -} -#endif -- GitLab