add optional replace syntax when merging includes

This commit is contained in:
Yonas Kolb 2017-09-25 13:23:47 +02:00
parent 957493855c
commit c9c589c5ee
4 changed files with 13 additions and 3 deletions

View File

@ -6,6 +6,8 @@ settingGroups:
MY_SETTING3: VALUE3
new:
MY_SETTING: VALUE
toReplace:REPLACE:
MY_SETTING2: VALUE2
targets:
NewTarget:
type: application
@ -13,4 +15,4 @@ targets:
IncludedTarget:
name: IncludedTargetNew
platform: tvOS
sources: Target
sources:REPLACE: NewSource

View File

@ -3,7 +3,11 @@ settingGroups:
test:
MY_SETTING1: VALUE1
MY_SETTING2: VALUE2
toReplace:
MY_SETTING1: VALUE1
targets:
IncludedTarget:
type: application
platform: iOS
sources:
- Target

View File

@ -52,7 +52,10 @@ public struct SpecLoader {
var merged = base
for (key, value) in dictionary {
if let dictionary = value as? JSONDictionary, let base = merged[key] as? JSONDictionary {
if key.hasSuffix(":REPLACE") {
let newKey = key.replacingOccurrences(of: ":REPLACE", with: "")
merged[newKey] = value
} else if let dictionary = value as? JSONDictionary, let base = merged[key] as? JSONDictionary {
merged[key] = merge(dictionary: dictionary, onto: base)
} else if let array = value as? [Any], let base = merged[key] as? [Any] {
merged[key] = base + array

View File

@ -39,9 +39,10 @@ func specLoadingTests() {
try expect(spec.settingGroups) == [
"test": Settings(dictionary: ["MY_SETTING1": "NEW VALUE", "MY_SETTING2": "VALUE2", "MY_SETTING3": "VALUE3"]),
"new": Settings(dictionary: ["MY_SETTING": "VALUE"]),
"toReplace": Settings(dictionary: ["MY_SETTING2": "VALUE2"]),
]
try expect(spec.targets) == [
Target(name: "IncludedTargetNew", type: .application, platform: .tvOS, sources: ["Target"]),
Target(name: "IncludedTargetNew", type: .application, platform: .tvOS, sources: ["NewSource"]),
Target(name: "NewTarget", type: .application, platform: .iOS),
]
}