Created
September 23, 2011 23:49
-
-
Save roberocity/1238734 to your computer and use it in GitHub Desktop.
General Config class for handling YAML files
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
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