Skip to content

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

Closed

Description

@kapso

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!

Activity

  1. added this to the 2.0.1 milestone on Jun 28, 2019
  2. pkuczynski commented on Aug 6, 2019

    @pkuczynski
    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

  3. supremebeing7 commented on Aug 7, 2019

    @supremebeing7
    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!
  4. pkuczynski commented on Aug 7, 2019

    @pkuczynski
    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions