Skip to content

Instantly share code, notes, and snippets.

@Antti
Created September 25, 2012 14:11
Show Gist options
  • Select an option

  • Save Antti/3782162 to your computer and use it in GitHub Desktop.

Select an option

Save Antti/3782162 to your computer and use it in GitHub Desktop.
Rails Application Config loader
# gem 'hashie'
begin
app_name = Rails.application.class.parent_name.downcase
file_path = File.join(Rails.root,'config',"#{app_name}.yml")
app_config = Hashie::Mash.new(YAML.load_file(file_path)).freeze
rescue Errno::ENOENT
raise "Can not find #{app_name.upcase} config file: #{file_path}"
rescue Psych::SyntaxError
Rails.logger.error "Can not parse #{app_name.upcase} config file: #{file_path}:"
puts "Can not parse #{app_name.upcase} config file: #{file_path}"
raise
end
Rails.application.config.send(:"#{app_name}=", app_config)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment