Skip to content

Instantly share code, notes, and snippets.

@acook
Created February 6, 2013 23:59
Show Gist options
  • Save acook/4727078 to your computer and use it in GitHub Desktop.
Save acook/4727078 to your computer and use it in GitHub Desktop.
Extensible configuration objects from YAML
module ConfigModule
def [] key
config.send key
end
def config
@config ||= load_config
end
def config_file file
@config_file = file
end
def namespace name
@namespace = name
end
def load_config
file = OpenStruct.new YAML.load_file(@config_file)
@namespace ? file[@namespace] : file
end
def method_missing name, *args, &block
config.send name, *args, &block
end
end
module ExampleConfig
extend ConfigModule
config_file './config/example.yml'
namespace Rails.env
def kanoodle
'ka' + config.noodle
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment