Skip to content

Commit 778a32b

Browse files
committed
Merge pull request #46 from qutheory/snapshot-06-06
update to 06-06
2 parents 29658ba + c5f3f97 commit 778a32b

File tree

8 files changed

+59
-85
lines changed

8 files changed

+59
-85
lines changed

.swift-version

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
3.0-preview-1-SNAPSHOT-2016-05-31-a
1+
DEVELOPMENT-SNAPSHOT-2016-06-06-a
2+

Package.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import PackageDescription
22

33
let package = Package(
4-
name: "Fluent"
4+
name: "Fluent",
5+
dependencies: [
6+
//Standards package. Contains protocols for cross-project compatability.
7+
.Package(url: "https://github.com/open-swift/C7.git", majorVersion: 0, minor: 8),
8+
9+
// Syntax for easily accessing values from generic data.
10+
.Package(url: "https://github.com/qutheory/polymorphic.git", majorVersion: 0, minor: 1)
11+
]
512
)

Sources/Fluent+C7.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import C7
2+
3+
public typealias StructuredData = C7.StructuredData

Sources/Fluent+Polymorphic.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@_exported import Polymorphic

Sources/Model.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,4 @@ extension Model {
134134

135135
return "[\(id)] \(readable)"
136136
}
137-
}
137+
}

Sources/SQL.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ extension Action {
169169
Allows optionals to be targeted
170170
in protocol extensions
171171
*/
172-
public protocol Extractable {
172+
private protocol Extractable {
173173
associatedtype Wrapped
174174
func extract() -> Wrapped?
175175
}
@@ -178,7 +178,7 @@ public protocol Extractable {
178178
Conforms `Optional`
179179
*/
180180
extension Optional: Extractable {
181-
public func extract() -> Wrapped? {
181+
private func extract() -> Wrapped? {
182182
return self
183183
}
184184
}

Sources/Value+Polymorphic.swift

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
extension Value {
2+
public var isNull: Bool {
3+
return structuredData.isNull
4+
}
5+
6+
public var bool: Bool? {
7+
return structuredData.bool
8+
}
9+
10+
public var float: Float? {
11+
return structuredData.float
12+
}
13+
14+
public var double: Double? {
15+
return structuredData.double
16+
}
17+
18+
public var int: Int? {
19+
return structuredData.int
20+
}
21+
22+
public var string: String? {
23+
return structuredData.string
24+
}
25+
26+
public var array: [Polymorphic]? {
27+
return structuredData.array
28+
}
29+
30+
public var object: [String: Polymorphic]? {
31+
return structuredData.object
32+
}
33+
}

Sources/Value.swift

Lines changed: 9 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -6,101 +6,30 @@ public protocol Value: CustomStringConvertible, Polymorphic {
66
var structuredData: StructuredData { get }
77
}
88

9-
public protocol Polymorphic {
10-
var int: Int? { get }
11-
var string: String? { get }
12-
var double: Double? { get }
13-
}
14-
15-
public enum StructuredData {
16-
case null
17-
case bool(Bool)
18-
case integer(Int)
19-
case double(Double)
20-
case string(String)
21-
case array([StructuredData])
22-
case dictionary([String: StructuredData])
23-
}
24-
25-
extension Value {
26-
public var string: String? {
27-
switch structuredData {
28-
case .bool(let bool):
29-
return "\(bool)"
30-
case .integer(let int):
31-
return "\(int)"
32-
case .double(let double):
33-
return "\(double)"
34-
case .string(let string):
35-
return "\(string)"
36-
default:
37-
return nil
38-
}
39-
}
40-
41-
public var int: Int? {
42-
switch structuredData {
43-
case .integer(let int):
44-
return int
45-
case .string(let string):
46-
return Int(string)
47-
case .double(let double):
48-
return Int(double)
49-
case .bool(let bool):
50-
return bool ? 1 : 0
51-
default:
52-
return nil
53-
}
54-
}
55-
56-
public var double: Double? {
57-
switch structuredData {
58-
case .double(let double):
59-
return double
60-
case .string(let string):
61-
return Double(string)
62-
case .integer(let int):
63-
return Double(int)
64-
case .bool(let bool):
65-
return bool ? 1.0 : 0.0
66-
default:
67-
return nil
68-
}
69-
}
70-
}
71-
72-
extension Value {
73-
public var description: String {
74-
return self.string ?? ""
75-
}
76-
}
77-
789
extension Int: Value {
7910
public var structuredData: StructuredData {
80-
return .integer(self)
81-
}
82-
}
83-
84-
extension Double: Value {
85-
public var structuredData: StructuredData {
86-
return .double(self)
11+
return .int(self)
8712
}
8813
}
8914

9015
extension String: Value {
9116
public var structuredData: StructuredData {
9217
return .string(self)
9318
}
19+
20+
public var description: String {
21+
return self
22+
}
9423
}
9524

96-
extension Bool: Value {
25+
extension Double: Value {
9726
public var structuredData: StructuredData {
98-
return .bool(self)
27+
return .double(self)
9928
}
10029
}
10130

102-
extension StructuredData: Value {
31+
extension Float: Value {
10332
public var structuredData: StructuredData {
104-
return self
33+
return .double(Double(self))
10534
}
10635
}

0 commit comments

Comments
 (0)