settingslogic icon indicating copy to clipboard operation
settingslogic copied to clipboard

Nested settings overwrite defaults

Open zetlan opened this issue 13 years ago • 12 comments

Consider this settings.yaml file:

defaults: &defaults
  foo:
    bar: "baz"
    q: "bert"

development:
  <<: *defaults
  foo:
    bar: "xyzzy"

The intention is to do a multi-level merge of the defaults, so that in development you get Settings.foo = {"baz" => "xyzzy", q => "bert"} -- in other words, dev selectively overwrites the settings hash tree.

What you get instead is Settings.foo = {"baz" => "xyzzy"} -- the merge operates on the "foo" key, and doesn't check to see whether the value of Settings.foo may be a hash.

I'm getting around this now by using naming conventions (i.e., all the "foo" settings are foo_something) and putting all config options on the top level, but it would be much cleaner if nested settings were selectively merged.

Incidentally, this may be more or less a duplicate of issues #4 and #16, and I think there's at least one pull request to address this issue already.

zetlan avatar Aug 16 '11 14:08 zetlan

:+1:

edrex-janrain avatar Oct 04 '12 22:10 edrex-janrain

:+1:

neersighted avatar Dec 27 '12 23:12 neersighted

real life issue with this bug:

defaults: 
  log: 
    file: /tmp/log.log
    level: 'WARN'

development: 
  log: 
    level: 'DEBUG'

first of all, that's not even valid YAML syntax, file and level need a " - " prefix to make a YAML list. , Even if you do this, when selecting 'development', the log file is not found. The whole log section gets overwritten, not the just the level key. NOT COOL! This bug alone makes settingslogic useless for me.

dlite922 avatar Jan 07 '13 21:01 dlite922

:+1:

TimPetricola avatar May 15 '13 11:05 TimPetricola

:+1:

sprad avatar May 27 '13 21:05 sprad

:+1:

tkawachi avatar Jun 06 '13 00:06 tkawachi

:+1:

johnagan avatar Sep 16 '13 18:09 johnagan

:+1:

defance avatar Oct 11 '13 11:10 defance

:+1:

mtarnovan avatar Oct 16 '13 19:10 mtarnovan

I forgot about an old fork of mine of settingslogic which does this: https://github.com/mtarnovan/settingslogic/commit/a03bf1ef0f6b783f2c059153a7d01d8768d29c88

This fork also introduces a dependency on Hash#deep_merge from active_support

mtarnovan avatar Oct 17 '13 10:10 mtarnovan

:+1:

cofiem avatar Jul 23 '14 05:07 cofiem

:+1:

ccurtisj avatar Aug 12 '14 17:08 ccurtisj