Skip to content

Instantly share code, notes, and snippets.

@vvlad
Created September 17, 2014 14:41
Show Gist options
  • Select an option

  • Save vvlad/aa940b60cbddc6f218db to your computer and use it in GitHub Desktop.

Select an option

Save vvlad/aa940b60cbddc6f218db to your computer and use it in GitHub Desktop.
config_for
#Backported from rails 4.2
def config_for(name)
yaml = Pathname.new("#{paths["config"].existent.first}/#{name}.yml")
if yaml.exist?
require "yaml"
require "erb"
(YAML.load(ERB.new(yaml.read).result) || {})[Rails.env] || {}
else
raise "Could not load configuration. No such file - #{yaml}"
end
rescue Psych::SyntaxError => e
raise "YAML syntax error occurred while parsing #{yaml}. " \
"Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \
"Error: #{e.message}"
end unless method_defined? :config_for
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment