Skip to content

Commit

Permalink
Merge pull request #46 from qutheory/snapshot-06-06
Browse files Browse the repository at this point in the history
update to 06-06
  • Loading branch information
tanner0101 committed Jun 8, 2016
2 parents 29658ba + c5f3f97 commit 778a32b
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 85 deletions.
3 changes: 2 additions & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
3.0-preview-1-SNAPSHOT-2016-05-31-a
DEVELOPMENT-SNAPSHOT-2016-06-06-a

9 changes: 8 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -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)
]
)
3 changes: 3 additions & 0 deletions Sources/Fluent+C7.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import C7

public typealias StructuredData = C7.StructuredData
1 change: 1 addition & 0 deletions Sources/Fluent+Polymorphic.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@_exported import Polymorphic
2 changes: 1 addition & 1 deletion Sources/Model.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,4 @@ extension Model {

return "[\(id)] \(readable)"
}
}
}
4 changes: 2 additions & 2 deletions Sources/SQL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?
}
Expand All @@ -178,7 +178,7 @@ public protocol Extractable {
Conforms `Optional`
*/
extension Optional: Extractable {
public func extract() -> Wrapped? {
private func extract() -> Wrapped? {
return self
}
}
Expand Down
33 changes: 33 additions & 0 deletions Sources/Value+Polymorphic.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
89 changes: 9 additions & 80 deletions Sources/Value.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,101 +6,30 @@ 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)
}
}

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))
}
}

0 comments on commit 778a32b

Please sign in to comment.