mirror of
https://github.com/yonaskolb/XcodeGen.git
synced 2026-03-18 20:02:25 +00:00
Move [PathProperty] resolver to spec loader file
This commit is contained in:
@@ -88,41 +88,6 @@ extension Spec {
|
||||
}
|
||||
}
|
||||
|
||||
extension Array where Element == PathProperty {
|
||||
func resolvingPaths(in jsonDictionary: JSONDictionary, relativeTo path: Path) -> JSONDictionary {
|
||||
var result = jsonDictionary
|
||||
|
||||
for pathProperty in self {
|
||||
switch pathProperty {
|
||||
case .string(let key):
|
||||
if let source = result[key] as? String {
|
||||
result[key] = (path + source).string
|
||||
} else if let source = result[key] as? [String] {
|
||||
result[key] = source.map { (path + $0).string }
|
||||
} else if let source = result[key] as? [String: String] {
|
||||
result[key] = source.mapValues { (path + $0).string }
|
||||
}
|
||||
case .dictionary(let pathProperties):
|
||||
for (key, dictionary) in result {
|
||||
if let source = dictionary as? JSONDictionary {
|
||||
result[key] = pathProperties.resolvingPaths(in: source, relativeTo: path)
|
||||
}
|
||||
}
|
||||
case .object(let key, let pathProperties):
|
||||
if let source = result[key] as? JSONDictionary {
|
||||
result[key] = pathProperties.resolvingPaths(in: source, relativeTo: path)
|
||||
} else if let source = result[key] as? [JSONDictionary] {
|
||||
result[key] = source.map { pathProperties.resolvingPaths(in: $0, relativeTo: path) }
|
||||
} else if let source = result[key] as? [String: JSONDictionary] {
|
||||
result[key] = source.mapValues { pathProperties.resolvingPaths(in: $0, relativeTo: path) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
extension Dictionary where Key == String, Value: Any {
|
||||
|
||||
func merged(onto other: Dictionary<Key, Value>) -> Dictionary<Key, Value> {
|
||||
|
||||
@@ -26,3 +26,38 @@ enum PathProperty {
|
||||
case dictionary([PathProperty])
|
||||
case object(String, [PathProperty])
|
||||
}
|
||||
|
||||
extension Array where Element == PathProperty {
|
||||
func resolvingPaths(in jsonDictionary: JSONDictionary, relativeTo path: Path) -> JSONDictionary {
|
||||
var result = jsonDictionary
|
||||
|
||||
for pathProperty in self {
|
||||
switch pathProperty {
|
||||
case .string(let key):
|
||||
if let source = result[key] as? String {
|
||||
result[key] = (path + source).string
|
||||
} else if let source = result[key] as? [String] {
|
||||
result[key] = source.map { (path + $0).string }
|
||||
} else if let source = result[key] as? [String: String] {
|
||||
result[key] = source.mapValues { (path + $0).string }
|
||||
}
|
||||
case .dictionary(let pathProperties):
|
||||
for (key, dictionary) in result {
|
||||
if let source = dictionary as? JSONDictionary {
|
||||
result[key] = pathProperties.resolvingPaths(in: source, relativeTo: path)
|
||||
}
|
||||
}
|
||||
case .object(let key, let pathProperties):
|
||||
if let source = result[key] as? JSONDictionary {
|
||||
result[key] = pathProperties.resolvingPaths(in: source, relativeTo: path)
|
||||
} else if let source = result[key] as? [JSONDictionary] {
|
||||
result[key] = source.map { pathProperties.resolvingPaths(in: $0, relativeTo: path) }
|
||||
} else if let source = result[key] as? [String: JSONDictionary] {
|
||||
result[key] = source.mapValues { pathProperties.resolvingPaths(in: $0, relativeTo: path) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user