diff --git a/.swift-version b/.swift-version index d4ca9281..d5989905 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1,2 @@ -3.0-preview-1-SNAPSHOT-2016-05-31-a +DEVELOPMENT-SNAPSHOT-2016-06-06-a + diff --git a/Package.swift b/Package.swift index b53360d0..5b7615f1 100644 --- a/Package.swift +++ b/Package.swift @@ -1,5 +1,12 @@ import PackageDescription let package = Package( - name: "Fluent" + name: "Fluent", + dependencies: [ + //Standards package. Contains protocols for cross-project compatability. + .Package(url: "https://github.com/open-swift/C7.git", majorVersion: 0, minor: 8), + + // Syntax for easily accessing values from generic data. + .Package(url: "https://github.com/qutheory/polymorphic.git", majorVersion: 0, minor: 1) + ] ) diff --git a/Sources/Fluent+C7.swift b/Sources/Fluent+C7.swift new file mode 100644 index 00000000..a5f6722e --- /dev/null +++ b/Sources/Fluent+C7.swift @@ -0,0 +1,3 @@ +import C7 + +public typealias StructuredData = C7.StructuredData \ No newline at end of file diff --git a/Sources/Fluent+Polymorphic.swift b/Sources/Fluent+Polymorphic.swift new file mode 100644 index 00000000..08fe28ba --- /dev/null +++ b/Sources/Fluent+Polymorphic.swift @@ -0,0 +1 @@ +@_exported import Polymorphic diff --git a/Sources/Model.swift b/Sources/Model.swift index 66006559..63aee4a3 100644 --- a/Sources/Model.swift +++ b/Sources/Model.swift @@ -134,4 +134,4 @@ extension Model { return "[\(id)] \(readable)" } -} +} \ No newline at end of file diff --git a/Sources/SQL.swift b/Sources/SQL.swift index bd1a07b2..024ea338 100644 --- a/Sources/SQL.swift +++ b/Sources/SQL.swift @@ -169,7 +169,7 @@ extension Action { Allows optionals to be targeted in protocol extensions */ -public protocol Extractable { +private protocol Extractable { associatedtype Wrapped func extract() -> Wrapped? } @@ -178,7 +178,7 @@ public protocol Extractable { Conforms `Optional` */ extension Optional: Extractable { - public func extract() -> Wrapped? { + private func extract() -> Wrapped? { return self } } diff --git a/Sources/Value+Polymorphic.swift b/Sources/Value+Polymorphic.swift new file mode 100644 index 00000000..a3496d1c --- /dev/null +++ b/Sources/Value+Polymorphic.swift @@ -0,0 +1,33 @@ +extension Value { + public var isNull: Bool { + return structuredData.isNull + } + + public var bool: Bool? { + return structuredData.bool + } + + public var float: Float? { + return structuredData.float + } + + public var double: Double? { + return structuredData.double + } + + public var int: Int? { + return structuredData.int + } + + public var string: String? { + return structuredData.string + } + + public var array: [Polymorphic]? { + return structuredData.array + } + + public var object: [String: Polymorphic]? { + return structuredData.object + } +} diff --git a/Sources/Value.swift b/Sources/Value.swift index 54f0f560..b6f49d78 100644 --- a/Sources/Value.swift +++ b/Sources/Value.swift @@ -6,84 +6,9 @@ public protocol Value: CustomStringConvertible, Polymorphic { var structuredData: StructuredData { get } } -public protocol Polymorphic { - var int: Int? { get } - var string: String? { get } - var double: Double? { get } -} - -public enum StructuredData { - case null - case bool(Bool) - case integer(Int) - case double(Double) - case string(String) - case array([StructuredData]) - case dictionary([String: StructuredData]) -} - -extension Value { - public var string: String? { - switch structuredData { - case .bool(let bool): - return "\(bool)" - case .integer(let int): - return "\(int)" - case .double(let double): - return "\(double)" - case .string(let string): - return "\(string)" - default: - return nil - } - } - - public var int: Int? { - switch structuredData { - case .integer(let int): - return int - case .string(let string): - return Int(string) - case .double(let double): - return Int(double) - case .bool(let bool): - return bool ? 1 : 0 - default: - return nil - } - } - - public var double: Double? { - switch structuredData { - case .double(let double): - return double - case .string(let string): - return Double(string) - case .integer(let int): - return Double(int) - case .bool(let bool): - return bool ? 1.0 : 0.0 - default: - return nil - } - } -} - -extension Value { - public var description: String { - return self.string ?? "" - } -} - extension Int: Value { public var structuredData: StructuredData { - return .integer(self) - } -} - -extension Double: Value { - public var structuredData: StructuredData { - return .double(self) + return .int(self) } } @@ -91,16 +16,20 @@ extension String: Value { public var structuredData: StructuredData { return .string(self) } + + public var description: String { + return self + } } -extension Bool: Value { +extension Double: Value { public var structuredData: StructuredData { - return .bool(self) + return .double(self) } } -extension StructuredData: Value { +extension Float: Value { public var structuredData: StructuredData { - return self + return .double(Double(self)) } }