twigkit/fig

Configuration loader that merges two Fig configuration trees

Closed this issue · 0 comments

The twigkit.fig.loader.MergeLoader takes in two twigkit.fig.Loader instances which it uses to load a new Fig tree by combining all configurations loaded from the two loaders. The two loaders are considered in sequence and all values found in the second loader will overwrite any existing values from the first loader when there are duplicate keys.

For example, consider two configuration trees

conf1
    root
        foo: bar
        bar: foo

conf2
    root
        foo: changed

Assume we have two twigkit.fig.loader.Loader instances, loader1 and loader2, where loader1 loads /conf1 whilst loader2 loads /conf2. Then an instance of Fig defined by

new Fig(new MergeLoader(loader1, loader2))

should contain root.foo = changed and also root.bar = foo.

Note: This works differently from when a new Fig instance is created from a sequence of Loader instances. In that case, whole configuration nodes completely override any nodes that were loaded by previous loaders. For example, suppose we have as in the example above

conf1
    root
        foo: bar
        bar: foo

conf2
    root
        foo: changed

and loader1 loads /conf1 whilst loader2 loads /conf2. Then an instance of Fig defined by

new Fig(loader1, loader2)

will contain root.foo = changed (correct) but not root.bar = foo (incorrect). This seems to be design in twigkit.fig.loader.PropertiesLoader.