Skip to content

Instantly share code, notes, and snippets.

@roberocity
Created September 23, 2011 23:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roberocity/1238734 to your computer and use it in GitHub Desktop.
Save roberocity/1238734 to your computer and use it in GitHub Desktop.
General Config class for handling YAML files
class Config
attr_reader :data, :env
def self.config_path
File.join('config')
end
def initialize(opts)
@env = opts[:env]
filename = opts[:filename]
@data = YAML::load_file(File.join(self.class.config_path,filename))
define_config_methods(data[env].keys)
end
def define_config_methods(names)
names.each do |name|
class_eval <<-EOS
def #{name}
data[env]['#{name}']
end
EOS
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment