config
config copied to clipboard
Extra config sources defined in initializer
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?
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 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?
@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.