From ad3e308d3680e28c5cce30a6b5312c73ee2d5d8a Mon Sep 17 00:00:00 2001 From: Mathew Huusko V Date: Wed, 29 May 2019 18:08:23 -0400 Subject: [PATCH] 0.8.1 --- Babel.podspec | 2 +- Sources/Decodable.swift | 24 ++++--- Sources/Operators.swift | 96 --------------------------- Xcode/Babel.playground/Contents.swift | 4 +- Xcode/Info.plist | 2 +- 5 files changed, 17 insertions(+), 111 deletions(-) diff --git a/Babel.podspec b/Babel.podspec index cf11cbd..f56f1d6 100644 --- a/Babel.podspec +++ b/Babel.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'Babel' - s.version = '0.8.0' + s.version = '0.8.1' s.summary = 'JSON! *Pure Swift*, failure driven, inferred *but unambiguous*, with powerful *but optional* operators.' s.license = { :type => 'MIT', :file => 'LICENSE' } diff --git a/Sources/Decodable.swift b/Sources/Decodable.swift index 5d3fef8..7a53daf 100644 --- a/Sources/Decodable.swift +++ b/Sources/Decodable.swift @@ -79,22 +79,12 @@ public extension Value { return try T.decode(self) } - func decode(type: T.Type = T.self, ignoreFailure: Bool = false) throws -> T? { - do { - return try T.decode(self) - } catch let error { - if ignoreFailure { return nil } - else { throw error } - } - } - func decode(type: T.Type = T.self, ignoreFailures: Bool = false) throws -> [T] { return try asArray().decode(ignoreFailures: ignoreFailures) } func decode( - keyType: K.Type = K.self, - valueType: V.Type = V.self, + keyType: K.Type = K.self, valueType: V.Type = V.self, ignoreFailures: Bool = false ) throws -> [K: V] { @@ -102,6 +92,18 @@ public extension Value { } } +extension Array: Decodable where Element: Decodable { + public static func _decode(_ value: Value) throws -> Array { + return try value.asArray().decode() + } +} + +extension Dictionary: Decodable where Key: Decodable, Value: Decodable { + public static func _decode(_ value: Babel.Value) throws -> Dictionary { + return try value.asDictionary().decode() + } +} + extension Bool: Decodable { public static func _decode(_ value: Value) throws -> Bool { return try value.asBool() } } diff --git a/Sources/Operators.swift b/Sources/Operators.swift index f7b8d0d..9ba1b4b 100644 --- a/Sources/Operators.swift +++ b/Sources/Operators.swift @@ -12,14 +12,6 @@ public func =>(lhs: Value, rhs: Int) throws -> T { return try (lhs => rhs).decode() } -public func =>(lhs: Value, rhs: Int) throws -> [T] { - return try (lhs => rhs).decode() -} - -public func =>(lhs: Value, rhs: Int) throws -> [K: V] { - return try (lhs => rhs).decode() -} - // MARK: Nil Chaining public func =>(lhs: Value?, rhs: Int) throws -> Value? { @@ -30,14 +22,6 @@ public func =>(lhs: Value?, rhs: Int) throws -> T? { return try (lhs => rhs)?.decode() } -public func =>(lhs: Value?, rhs: Int) throws -> [T]? { - return try (lhs => rhs)?.decode() -} - -public func =>(lhs: Value?, rhs: Int) throws -> [K: V]? { - return try (lhs => rhs)?.decode() -} - // MARK: - Array (Accept Null) - public func =>?(lhs: Value, rhs: Int) throws -> Value? { @@ -48,14 +32,6 @@ public func =>?(lhs: Value, rhs: Int) throws -> T? { return try (lhs =>? rhs)?.decode() } -public func =>?(lhs: Value, rhs: Int) throws -> [T]? { - return try (lhs =>? rhs)?.decode() -} - -public func =>?(lhs: Value, rhs: Int) throws -> [K: V]? { - return try (lhs =>? rhs)?.decode() -} - // MARK: Nil Chaining public func =>?(lhs: Value?, rhs: Int) throws -> Value? { @@ -66,14 +42,6 @@ public func =>?(lhs: Value?, rhs: Int) throws -> T? { return try (lhs =>? rhs)?.decode() } -public func =>?(lhs: Value?, rhs: Int) throws -> [T]? { - return try (lhs =>? rhs)?.decode() -} - -public func =>?(lhs: Value?, rhs: Int) throws -> [K: V]? { - return try (lhs =>? rhs)?.decode() -} - // MARK: - Array (Accept Out of Bounds or Null) - public func =>??(lhs: Value, rhs: Int) throws -> Value? { @@ -84,14 +52,6 @@ public func =>??(lhs: Value, rhs: Int) throws -> T? { return try (lhs =>?? rhs)?.decode() } -public func =>??(lhs: Value, rhs: Int) throws -> [T]? { - return try (lhs =>?? rhs)?.decode() -} - -public func =>??(lhs: Value, rhs: Int) throws -> [K: V]? { - return try (lhs =>?? rhs)?.decode() -} - // MARK: Nil Chaining public func =>??(lhs: Value?, rhs: Int) throws -> Value? { @@ -102,14 +62,6 @@ public func =>??(lhs: Value?, rhs: Int) throws -> T? { return try (lhs =>?? rhs)?.decode() } -public func =>??(lhs: Value?, rhs: Int) throws -> [T]? { - return try (lhs =>?? rhs)?.decode() -} - -public func =>??(lhs: Value?, rhs: Int) throws -> [K: V]? { - return try (lhs =>?? rhs)?.decode() -} - // MARK: - Dictionary - public func =>(lhs: Value, rhs: String) throws -> Value { @@ -120,14 +72,6 @@ public func =>(lhs: Value, rhs: String) throws -> T { return try (lhs => rhs).decode() } -public func =>(lhs: Value, rhs: String) throws -> [T] { - return try (lhs => rhs).decode() -} - -public func =>(lhs: Value, rhs: String) throws -> [K: V] { - return try (lhs => rhs).decode() -} - // MARK: Nil Chaining public func =>(lhs: Value?, rhs: String) throws -> Value? { @@ -138,14 +82,6 @@ public func =>(lhs: Value?, rhs: String) throws -> T? { return try (lhs => rhs)?.decode() } -public func =>(lhs: Value?, rhs: String) throws -> [T]? { - return try (lhs => rhs)?.decode() -} - -public func =>(lhs: Value?, rhs: String) throws -> [K: V]? { - return try (lhs => rhs)?.decode() -} - // MARK: - Dictionary (Accept Null) - public func =>?(lhs: Value, rhs: String) throws -> Value? { @@ -156,14 +92,6 @@ public func =>?(lhs: Value, rhs: String) throws -> T? { return try (lhs =>? rhs)?.decode() } -public func =>?(lhs: Value, rhs: String) throws -> [T]? { - return try (lhs =>? rhs)?.decode() -} - -public func =>?(lhs: Value, rhs: String) throws -> [K: V]? { - return try (lhs =>? rhs)?.decode() -} - // MARK: Nil Chaining public func =>?(lhs: Value?, rhs: String) throws -> Value? { @@ -174,14 +102,6 @@ public func =>?(lhs: Value?, rhs: String) throws -> T? { return try (lhs =>? rhs)?.decode() } -public func =>?(lhs: Value?, rhs: String) throws -> [T]? { - return try (lhs =>? rhs)?.decode() -} - -public func =>?(lhs: Value?, rhs: String) throws -> [K: V]? { - return try (lhs =>? rhs)?.decode() -} - // MARK: - Dictionary (Accept Missing Key or Null) - public func =>??(lhs: Value, rhs: String) throws -> Value? { @@ -192,14 +112,6 @@ public func =>??(lhs: Value, rhs: String) throws -> T? { return try (lhs =>?? rhs)?.decode() } -public func =>??(lhs: Value, rhs: String) throws -> [T]? { - return try (lhs =>?? rhs)?.decode() -} - -public func =>??(lhs: Value, rhs: String) throws -> [K: V]? { - return try (lhs =>?? rhs)?.decode() -} - // MARK: Nil Chaining public func =>??(lhs: Value?, rhs: String) throws -> Value? { @@ -209,11 +121,3 @@ public func =>??(lhs: Value?, rhs: String) throws -> Value? { public func =>??(lhs: Value?, rhs: String) throws -> T? { return try (lhs =>?? rhs)?.decode() } - -public func =>??(lhs: Value?, rhs: String) throws -> [T]? { - return try (lhs =>?? rhs)?.decode() -} - -public func =>??(lhs: Value?, rhs: String) throws -> [K: V]? { - return try (lhs =>?? rhs)?.decode() -} diff --git a/Xcode/Babel.playground/Contents.swift b/Xcode/Babel.playground/Contents.swift index a9c3756..ec74f2b 100644 --- a/Xcode/Babel.playground/Contents.swift +++ b/Xcode/Babel.playground/Contents.swift @@ -117,7 +117,7 @@ public struct YouTubeResponse: Decodable { case .functionExplicit: return try YouTubeResponse( apiVersion: value.asDictionary().valueFor("apiVersion").asDouble(), - data: value.asDictionary().maybeValueFor("data", nilOnNull: true, throwOnMissing: true)?.decode(type: YouTubeData.self, ignoreFailure: false) + data: value.asDictionary().maybeValueFor("data", nilOnNull: true, throwOnMissing: true)?.decode(type: YouTubeData.self) ) case .unwrappingAndChecking: @@ -165,7 +165,7 @@ public struct YouTubeData: Decodable { case .functionExplicit: return try YouTubeData( totalItems: value.asDictionary().valueFor("totalItems").asInt(), - firstItem: value.asDictionary().valueFor("items").asArray().maybeValueAt(0, nilOnNull: true, throwOnMissing: false)?.decode(type: YouTubeDataItem.self, ignoreFailure: false), + firstItem: value.asDictionary().valueFor("items").asArray().maybeValueAt(0, nilOnNull: true, throwOnMissing: false)?.decode(type: YouTubeDataItem.self), items: value.asDictionary().valueFor("items").asArray().decode(type: YouTubeDataItem.self, ignoreFailures: false) ) diff --git a/Xcode/Info.plist b/Xcode/Info.plist index 5d7827c..093aab3 100644 --- a/Xcode/Info.plist +++ b/Xcode/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 0.8.0 + 0.8.1 CFBundleSignature ???? CFBundleVersion