Skip to content

Instantly share code, notes, and snippets.

@jphenow
Created July 3, 2013 21:15
Show Gist options
  • Save jphenow/5922894 to your computer and use it in GitHub Desktop.
Save jphenow/5922894 to your computer and use it in GitHub Desktop.
Rails config file Object I like to use
class ConfigFile
attr_reader :config_name
attr_reader :context
def self.read_with_env(*args)
new(*args).read_with_env
end
def self.read(*args)
new(*args).read
end
def initialize(config_name, options = {})
@config_name = config_name.to_s
@context = (options[:context] || "config").to_s
@bind = options[:binding]
end
def read
yamled
end
def read_with_env
read[Rails.env]
end
private
def yamled
YAML.load(erbed)
end
def erbed
ERB.new(file).result(@bind || binding)
end
def file
@file ||= File.read(Rails.root.join(context, "#{config_name}.yml"))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment