Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide the way to override attributes of settings #42

Open
zalun opened this issue Jun 1, 2012 · 4 comments
Open

Provide the way to override attributes of settings #42

zalun opened this issue Jun 1, 2012 · 4 comments

Comments

@zalun
Copy link

zalun commented Jun 1, 2012

I'm trying to provide several configuration files which are overriding each other

config-default.json's settings are overriden by config-{DEV_ENV}.json and these by config-local.json

I'm using this:

conf.add('local-file', {'type': 'file', file: path.join(__dirname, './config-local.json')});
var current_env = process.env['DEV_ENV'] || 'development';
conf.add('env-file', {'type': 'file', file: path.join(__dirname, './config-' + current_env + '.json')});
conf.add('default-file', {'type': 'file', file: path.join(__dirname, './config-default.json')});

It's working well, however I'm unable to override parts of the object:
if config-default.json has a setting settingA defined in such way:

{
    "settingA": {
        "attributeA": "valueA",
        "attributeB": "valueB"
    }
}

it can be accessed by conf.get('settingA:attributeA'). I wish to override just this value in any other file. This is not working for obvious reasons (overrides entire setting):

{
    "settingA": {
        "attributeA": "localValueA"
    } 
}

But there is a syntax which isn't used and could work well:

{
    "settingA:attributeA": "localValueA"
}

Please tell me it's sane and if I'm using your lib in the right way.

@domguinard
Copy link

+1 for the question... facing the same...

@bmeck
Copy link
Contributor

bmeck commented Sep 7, 2012

does .merge({'settingA', {'attributeA': 'localValueA'}) do as you want?

@indexzero
Copy link
Owner

This is by design. There is no way exposed to force the hierarchy to not merge objects from various providers. To work around this in the config you wish to use to override entirely put:

  {
    "settingA": {
        "attributeA": "valueA",
        "attributeB": null
    }
}

If you could provide a failing test for this that would be really helpful.

@mansona
Copy link
Contributor

mansona commented Feb 26, 2017

Does this test cover the use case: #255

It's not failing but I came across something very similar and thought it was a bug but turned out it was an issue on my end. Me writing that test was a way for me to confirm it was my issue 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants