Created
September 25, 2012 14:11
-
-
Save Antti/3782162 to your computer and use it in GitHub Desktop.
Rails Application Config loader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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