Skip to content

Commit f6b5932

Browse files
committed
Refactoring started
1 parent fa7aacf commit f6b5932

1 file changed

Lines changed: 49 additions & 7 deletions

File tree

Sources/ProjectSpec/SwiftPackage.swift

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,23 +106,65 @@ extension SwiftPackage.VersionRequirement: JSONUtilities.JSONObjectConvertible {
106106

107107
public init(jsonDictionary: JSONDictionary) throws {
108108
if jsonDictionary["exactVersion"] != nil {
109-
self = try .exact(jsonDictionary.json(atKeyPath: "exactVersion"))
109+
do {
110+
let exactVersion: String = try jsonDictionary.json(atKeyPath: "exactVersion")
111+
self = .exact(exactVersion)
112+
} catch {
113+
let exactVersion: Double = try jsonDictionary.json(atKeyPath: "exactVersion")
114+
self = .exact(String(exactVersion))
115+
}
110116
} else if jsonDictionary["version"] != nil {
111-
self = try .exact(jsonDictionary.json(atKeyPath: "version"))
117+
do {
118+
let version: String = try jsonDictionary.json(atKeyPath: "version")
119+
self = .exact(version)
120+
} catch {
121+
let version: Double = try jsonDictionary.json(atKeyPath: "version")
122+
self = .exact(String(version))
123+
}
112124
} else if jsonDictionary["revision"] != nil {
113-
self = try .revision(jsonDictionary.json(atKeyPath: "revision"))
125+
do {
126+
let revision: String = try jsonDictionary.json(atKeyPath: "revision")
127+
self = .exact(revision)
128+
} catch {
129+
let revision: Double = try jsonDictionary.json(atKeyPath: "revision")
130+
self = .exact(String(revision))
131+
}
114132
} else if jsonDictionary["branch"] != nil {
115-
self = try .branch(jsonDictionary.json(atKeyPath: "branch"))
133+
do {
134+
let branch: String = try jsonDictionary.json(atKeyPath: "branch")
135+
self = .exact(branch)
136+
} catch {
137+
let branch: Double = try jsonDictionary.json(atKeyPath: "branch")
138+
self = .exact(String(branch))
139+
}
116140
} else if jsonDictionary["minVersion"] != nil && jsonDictionary["maxVersion"] != nil {
117141
let minimum: String = try jsonDictionary.json(atKeyPath: "minVersion")
118142
let maximum: String = try jsonDictionary.json(atKeyPath: "maxVersion")
119143
self = .range(from: minimum, to: maximum)
120144
} else if jsonDictionary["minorVersion"] != nil {
121-
self = try .upToNextMinorVersion(jsonDictionary.json(atKeyPath: "minorVersion"))
145+
do {
146+
let minorVersion: String = try jsonDictionary.json(atKeyPath: "minorVersion")
147+
self = .exact(minorVersion)
148+
} catch {
149+
let minorVersion: Double = try jsonDictionary.json(atKeyPath: "minorVersion")
150+
self = .exact(String(minorVersion))
151+
}
122152
} else if jsonDictionary["majorVersion"] != nil {
123-
self = try .upToNextMajorVersion(jsonDictionary.json(atKeyPath: "majorVersion"))
153+
do {
154+
let majorVersion: String = try jsonDictionary.json(atKeyPath: "majorVersion")
155+
self = .exact(majorVersion)
156+
} catch {
157+
let majorVersion: Double = try jsonDictionary.json(atKeyPath: "majorVersion")
158+
self = .exact(String(majorVersion))
159+
}
124160
} else if jsonDictionary["from"] != nil {
125-
self = try .upToNextMajorVersion(jsonDictionary.json(atKeyPath: "from"))
161+
do {
162+
let from: String = try jsonDictionary.json(atKeyPath: "from")
163+
self = .exact(from)
164+
} catch {
165+
let from: Double = try jsonDictionary.json(atKeyPath: "from")
166+
self = .exact(String(from))
167+
}
126168
} else {
127169
throw SpecParsingError.unknownPackageRequirement(jsonDictionary)
128170
}

0 commit comments

Comments
 (0)