config icon indicating copy to clipboard operation
config copied to clipboard

Extra config sources defined in initializer

Open DannyBen opened this issue 9 years ago • 3 comments

Hi,

Not sure if this is implemented and I haven't found it or not.

I know there is a way to create an initializer that adds another settings file and reloads.

Although this is a good feature that can solve my use case of loading config file per client, it feels a little "after the fact patch" since I dont really need it to be "at run time".

I was wondering if it will be difficult to add a more natural way of adding settings file at initialization time, simply as an option to the initializer, something like:

Config.setup do |config|
  config.const_name = "Settings"
  config.add_source = "config/settings/#{ENV['CLIENT_NAME']}.yml"
end

As a side note - where is the documentation of all the allowed options in the Config.setup block?

DannyBen avatar Jan 01 '16 06:01 DannyBen

Settings constant is a singleton shared across all request to your Rails app. That means it would load your client config once when the server starts (single Rails server instance serving single client). Is this what you are trying to achieve?

In contrast you might want to apply custom client settings per every request, so one server can respond to multiple clients...

pkuczynski avatar May 12 '16 13:05 pkuczynski

@pkuczynski it would be nice improvement in terms of splitting different config files by domains/technologies. Big config file is difficult for reading/understanding, is there a chance for implementing this feature?

ilyakarol avatar Jul 16 '19 08:07 ilyakarol

@ilyakorol you can add sources in runtime. It should not be hard to do the same on the initializer level as @DannyBen suggested:

Config.setup do |config|
  config.const_name = "Settings"
  config.extra_sources = [...]
end

Feel free to create PR for this feature and we will merge it.

pkuczynski avatar Jul 16 '19 09:07 pkuczynski