Skip to content

Commit

Permalink
0.8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mhuusko5 committed May 29, 2019
1 parent 5925907 commit ad3e308
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 111 deletions.
2 changes: 1 addition & 1 deletion Babel.podspec
Original file line number Diff line number Diff line change
@@ -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' }
Expand Down
24 changes: 13 additions & 11 deletions Sources/Decodable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,29 +79,31 @@ public extension Value {
return try T.decode(self)
}

func decode<T: Decodable>(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<T: Decodable>(type: T.Type = T.self, ignoreFailures: Bool = false) throws -> [T] {
return try asArray().decode(ignoreFailures: ignoreFailures)
}

func decode<K: Decodable, V: Decodable>(
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] {

return try asDictionary().decode(ignoreFailures: ignoreFailures)
}
}

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() }
}
Expand Down
96 changes: 0 additions & 96 deletions Sources/Operators.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ public func =><T: Decodable>(lhs: Value, rhs: Int) throws -> T {
return try (lhs => rhs).decode()
}

public func =><T: Decodable>(lhs: Value, rhs: Int) throws -> [T] {
return try (lhs => rhs).decode()
}

public func =><K: Decodable, V: Decodable>(lhs: Value, rhs: Int) throws -> [K: V] {
return try (lhs => rhs).decode()
}

// MARK: Nil Chaining

public func =>(lhs: Value?, rhs: Int) throws -> Value? {
Expand All @@ -30,14 +22,6 @@ public func =><T: Decodable>(lhs: Value?, rhs: Int) throws -> T? {
return try (lhs => rhs)?.decode()
}

public func =><T: Decodable>(lhs: Value?, rhs: Int) throws -> [T]? {
return try (lhs => rhs)?.decode()
}

public func =><K: Decodable, V: Decodable>(lhs: Value?, rhs: Int) throws -> [K: V]? {
return try (lhs => rhs)?.decode()
}

// MARK: - Array (Accept Null) -

public func =>?(lhs: Value, rhs: Int) throws -> Value? {
Expand All @@ -48,14 +32,6 @@ public func =>?<T: Decodable>(lhs: Value, rhs: Int) throws -> T? {
return try (lhs =>? rhs)?.decode()
}

public func =>?<T: Decodable>(lhs: Value, rhs: Int) throws -> [T]? {
return try (lhs =>? rhs)?.decode()
}

public func =>?<K: Decodable, V: Decodable>(lhs: Value, rhs: Int) throws -> [K: V]? {
return try (lhs =>? rhs)?.decode()
}

// MARK: Nil Chaining

public func =>?(lhs: Value?, rhs: Int) throws -> Value? {
Expand All @@ -66,14 +42,6 @@ public func =>?<T: Decodable>(lhs: Value?, rhs: Int) throws -> T? {
return try (lhs =>? rhs)?.decode()
}

public func =>?<T: Decodable>(lhs: Value?, rhs: Int) throws -> [T]? {
return try (lhs =>? rhs)?.decode()
}

public func =>?<K: Decodable, V: Decodable>(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? {
Expand All @@ -84,14 +52,6 @@ public func =>??<T: Decodable>(lhs: Value, rhs: Int) throws -> T? {
return try (lhs =>?? rhs)?.decode()
}

public func =>??<T: Decodable>(lhs: Value, rhs: Int) throws -> [T]? {
return try (lhs =>?? rhs)?.decode()
}

public func =>??<K: Decodable, V: Decodable>(lhs: Value, rhs: Int) throws -> [K: V]? {
return try (lhs =>?? rhs)?.decode()
}

// MARK: Nil Chaining

public func =>??(lhs: Value?, rhs: Int) throws -> Value? {
Expand All @@ -102,14 +62,6 @@ public func =>??<T: Decodable>(lhs: Value?, rhs: Int) throws -> T? {
return try (lhs =>?? rhs)?.decode()
}

public func =>??<T: Decodable>(lhs: Value?, rhs: Int) throws -> [T]? {
return try (lhs =>?? rhs)?.decode()
}

public func =>??<K: Decodable, V: Decodable>(lhs: Value?, rhs: Int) throws -> [K: V]? {
return try (lhs =>?? rhs)?.decode()
}

// MARK: - Dictionary -

public func =>(lhs: Value, rhs: String) throws -> Value {
Expand All @@ -120,14 +72,6 @@ public func =><T: Decodable>(lhs: Value, rhs: String) throws -> T {
return try (lhs => rhs).decode()
}

public func =><T: Decodable>(lhs: Value, rhs: String) throws -> [T] {
return try (lhs => rhs).decode()
}

public func =><K: Decodable, V: Decodable>(lhs: Value, rhs: String) throws -> [K: V] {
return try (lhs => rhs).decode()
}

// MARK: Nil Chaining

public func =>(lhs: Value?, rhs: String) throws -> Value? {
Expand All @@ -138,14 +82,6 @@ public func =><T: Decodable>(lhs: Value?, rhs: String) throws -> T? {
return try (lhs => rhs)?.decode()
}

public func =><T: Decodable>(lhs: Value?, rhs: String) throws -> [T]? {
return try (lhs => rhs)?.decode()
}

public func =><K: Decodable, V: Decodable>(lhs: Value?, rhs: String) throws -> [K: V]? {
return try (lhs => rhs)?.decode()
}

// MARK: - Dictionary (Accept Null) -

public func =>?(lhs: Value, rhs: String) throws -> Value? {
Expand All @@ -156,14 +92,6 @@ public func =>?<T: Decodable>(lhs: Value, rhs: String) throws -> T? {
return try (lhs =>? rhs)?.decode()
}

public func =>?<T: Decodable>(lhs: Value, rhs: String) throws -> [T]? {
return try (lhs =>? rhs)?.decode()
}

public func =>?<K: Decodable, V: Decodable>(lhs: Value, rhs: String) throws -> [K: V]? {
return try (lhs =>? rhs)?.decode()
}

// MARK: Nil Chaining

public func =>?(lhs: Value?, rhs: String) throws -> Value? {
Expand All @@ -174,14 +102,6 @@ public func =>?<T: Decodable>(lhs: Value?, rhs: String) throws -> T? {
return try (lhs =>? rhs)?.decode()
}

public func =>?<T: Decodable>(lhs: Value?, rhs: String) throws -> [T]? {
return try (lhs =>? rhs)?.decode()
}

public func =>?<K: Decodable, V: Decodable>(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? {
Expand All @@ -192,14 +112,6 @@ public func =>??<T: Decodable>(lhs: Value, rhs: String) throws -> T? {
return try (lhs =>?? rhs)?.decode()
}

public func =>??<T: Decodable>(lhs: Value, rhs: String) throws -> [T]? {
return try (lhs =>?? rhs)?.decode()
}

public func =>??<K: Decodable, V: Decodable>(lhs: Value, rhs: String) throws -> [K: V]? {
return try (lhs =>?? rhs)?.decode()
}

// MARK: Nil Chaining

public func =>??(lhs: Value?, rhs: String) throws -> Value? {
Expand All @@ -209,11 +121,3 @@ public func =>??(lhs: Value?, rhs: String) throws -> Value? {
public func =>??<T: Decodable>(lhs: Value?, rhs: String) throws -> T? {
return try (lhs =>?? rhs)?.decode()
}

public func =>??<T: Decodable>(lhs: Value?, rhs: String) throws -> [T]? {
return try (lhs =>?? rhs)?.decode()
}

public func =>??<K: Decodable, V: Decodable>(lhs: Value?, rhs: String) throws -> [K: V]? {
return try (lhs =>?? rhs)?.decode()
}
4 changes: 2 additions & 2 deletions Xcode/Babel.playground/Contents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
)

Expand Down
2 changes: 1 addition & 1 deletion Xcode/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.8.0</string>
<string>0.8.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down

0 comments on commit ad3e308

Please sign in to comment.