-
-
Notifications
You must be signed in to change notification settings - Fork 235
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
Rails integration does not allow multiple YAML files to be specified in the first load #352
Comments
I have two suggestions about interface of the feature functionality: Convention Over Configuration Approach:
Extending Configuration: Config.setup do |config|
config.process_settings_files do |settings_files|
# Add files to the beginning of the list
settings_files.unshift('config/settings/default/separated_config.yml')
# Append files to the end of the list
settings_files << 'config/settings/default/another/separated_config.yml'
# Or redefine settings_files
settings_files = ['some_config.yml']
settings_files
end
end This approach offers flexibility in configuring the loading order, ensuring users can prioritize their configuration files as needed. I can try to prepare PR |
I think you're hitting on all of things that are important to consider
I think the idea of being able to have control over the order over which files are loaded, and I think the suggested API for Config.setup do |config|
config.default_settings_sources = [
"config/settings.yaml"
]
end The default value for the new Config.setup do |config|
config.default_settings_sources = do
settings_files = Config.setting_files(::Rails.root.join('config'), ::Rails.env)
settings_files.unshift('config/settings/default/separated_config.yml')
settings_files << 'config/settings/default/another/separated_config.yml'
end
end What do you think? |
Thinking about it a bit more, I guess both approaches depart from what I think is the original design of the gem:
This distinction is interesting to me because I'm not 100% bought-in that this present distinction between config and data (the actual list of files) is the perfect API, but I also want to respect the precedent and I think being able to specify the list of settings files in both Therefore, I'm thinking the most straightforward solution to this problem is to just make it so that if a Rails user calls So for Rails uses that are completely bought in to the default list of settings files, they don't have to call |
I understand your position and agree that there is a reason to stick to the original plan. I like the idea of having Railtie not call I tried to think about how this could break backward compatibility, but I couldn't find any issues. Then the project's config might look like this: # app/initializers/config.rb in a Rails project
Config.setup do |config|
Config.load_and_set_settings(file_list)
end And if the configuration is already defined ( class Railtie < ::Rails::Railtie
def preload
...
return if Object.const_defined?(Config.const_name)
# Parse the settings before any of the initializers
Config.load_and_set_settings(
Config.setting_files(::Rails.root.join('config'), ::Rails.env)
)
... |
Yeah, that's perfect. Would you be interested in opening a PR? |
Yes, I will try |
I'm not found a way to test it yet. I need to first execute the But all specs runs after |
Yeah, there's not a good existing test pattern to use for this case. There are a few Rails apps in Without completely reorganizing the test suite, the most straightforward approach I see is to test the Railtie behavior is something like
We can rinse and repeat this pattern for a few tests
|
Thank you for great advice! I added tests |
In Rails projects,
config/initializers/config.rb
can be used to configure this gem, but the Railtie performs the actual first load of the settings files. The Railtie doesn't offer a way to specify additional settings sources (for example, multiple YAML files).It's possible to specify additional settings files today if users use a separate initializer, but this isn't always convenient because it essentially means that settings are loaded twice (and both times must satisfy the configured schema or contract) and because the initializer runs much later in the Rails boot process (so it's not available when evaluating some files like
config/environments/production.rb
)Related:
setup
block executed #244The text was updated successfully, but these errors were encountered: