Created
September 17, 2014 14:41
-
-
Save vvlad/aa940b60cbddc6f218db to your computer and use it in GitHub Desktop.
config_for
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
| #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