class Rails::Application

def config_for(name, env: Rails.env)

# => { baz: 1, qux: 2 }
Rails.application.config_for(:example)[:foo][:bar]
# development environment

qux: 2
bar:
foo:
development:

baz: 1
bar:
foo:
shared:
# config/example.yml

# merged with the environment configuration
# You can also store configurations in a shared section which will be

end
config.middleware.use ExceptionNotifier, config_for(:exception_notification)
Rails.application.configure do
# config/environments/production.rb

namespace: my_app_development
url: http://localhost:3001
development:

namespace: my_app_production
url: http://127.0.0.1:8080
production:
# config/exception_notification.yml:

Examples:

Convenience for loading config/foo.yml for the current Rails env.
def config_for(name, env: Rails.env)
  yaml = name.is_a?(Pathname) ? name : Pathname.new("#{paths["config"].existent.first}/#{name}.yml")
  if yaml.exist?
    require "erb"
    all_configs    = ActiveSupport::ConfigurationFile.parse(yaml).deep_symbolize_keys
    config, shared = all_configs[env.to_sym], all_configs[:shared]
    if shared
      config = {} if config.nil? && shared.is_a?(Hash)
      if config.is_a?(Hash) && shared.is_a?(Hash)
        config = shared.deep_merge(config)
      elsif config.nil?
        config = shared
      end
    end
    if config.is_a?(Hash)
      config = ActiveSupport::OrderedOptions.new.update(config)
    end
    config
  else
    raise "Could not load configuration. No such file - #{yaml}"
  end
end