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

Settings const name is not available right after Config.setup #187

Closed
kapso opened this issue Dec 13, 2017 · 3 comments
Closed

Settings const name is not available right after Config.setup #187

kapso opened this issue Dec 13, 2017 · 3 comments

Comments

@kapso
Copy link

kapso commented Dec 13, 2017

I am trying to access Settings const name in config.rb right after Config.setup, but getting an error?

*/initializers/config.rb

Config.setup do |config|
  config.const_name = 'Settings'
end

# Following results in an error - uninitialized constant Settings (NameError)
Settings.add_source!("#{Rails.root}/config/tune.yml")
Settings.reload!
@pkuczynski
Copy link
Member

This is not a valid way of doing, what you try to do. add_source should be called outside of initializer...

If your case is still needed we could add an option extra_sources to add additional sources. But in general idea behind this gem was to stick with following pattern: https://github.com/railsconfig/config/blob/master/lib/config.rb#L58

@supremebeing7
Copy link
Contributor

Since this is 1.5 years old I'm assuming this is probably resolved by now, but FWIW @kapso, you could create a separate initializer to load the tune.yml sources. I think something like this should work:

*/initializers/config.rb

Config.setup do |config|
  config.const_name = 'Settings'
end

*/initializers/tune.rb

Settings.add_source!("#{Rails.root}/config/tune.yml")
Settings.reload!

@pkuczynski
Copy link
Member

Yes, that could be a workaround for now. Closing this until further interest from anybody...

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

No branches or pull requests

3 participants