markbates / configatron

A super cool, simple, and feature rich configuration system for Ruby apps.

Home Page:http://www.metabates.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to share a piece of config

jlecour opened this issue · comments

Hi,

I'd like to be able to have some common parts shared (and eventually overwritten) by other parts of the configuration. Example :

configatron.shared.a = 'foo'
configatron.shared.b = 'bar'
configatron.shared.c = 'baz'

configatron.another = configatron.shared
configatron.another.d = 'qux'

configatron.yet_another = configatron.shared
configatron.yet_another.a = 'azerty'

If the configuration is to be copied, we could use configatron.another = configatron.shared.dup. An overwrite wold change only the copied value.

But if it is to be aliases, we could use configatron.another = configatron.shared. An overwrite would change the original value and be reflected in all aliases.

Is such a thing crazy?
I'd have real use case.

I don't think it's crazy. Submit a PR for a dup method and I'll check it out.

In the new way things work, each Configatron::Store has a pointer to its RootStore, so assigning in configatron.another = configatron.shared won't quite do what you want.

Options include:

  1. Somehow make the RootStore pointer behave more like a cached value. Invalidate that cache upon assignment.
  2. Don't support #dup, but instead make #to_hash return a fully serialized hash (rather than the behavior right now, which returns subconfigatron objects):
>> configatron.foo.bar = 'hi'
=> "hi"
>> configatron.to_hash
=> {:foo=>configatron.foo.bar = "hi"}

You could then use configure_from_hash to copy in the data.

I lean towards 2, as I think it's a more explicit pattern anyway, and this is an uncommon (though legit) use-case. Thoughts?

We now have a to_hash that works (#74). I'm going to mark this as resolved.