Created
November 30, 2009 18:34
-
-
Save dougal/245623 to your computer and use it in GitHub Desktop.
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
# Rails Config. | |
# Copyrighted(c) Douglas F Shearer 2009 | |
# Licensed under The MIT License. | |
# http://douglasfshearer.com/blog/simple-rails-config | |
site: | |
url: http://example.com | |
authentication: | |
username: [email protected] | |
password: myhackproofpassword | |
flickr: | |
api_key: d3c3576398a4876c920553b714bc177f | |
username: flickrusername | |
# Akismet. | |
wordpress: | |
api_key: 876c920553b7 |
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
# Rails Config Loader. | |
# Copyrighted(c) Douglas F Shearer 2009 | |
# Licensed under The MIT License. | |
# http://douglasfshearer.com/blog/simple-rails-config | |
module Config | |
class ConfigStore | |
# Takes a hash as an argument. | |
# If this hash contains other hashes, these too will turned into | |
# ConfigStore objects. | |
def initialize(contents) | |
@contents = contents | |
@contents.each do |k, v| | |
if v.is_a?(Hash) | |
@contents[k] = self.class.new(v) | |
end | |
end | |
end | |
def method_missing(sym, *args) | |
@contents[sym.to_s] || super | |
end | |
end | |
def config | |
@@config ||= ConfigStore.new(YAML.load_file("#{RAILS_ROOT}/config/app.yml")) | |
end | |
end | |
include Config |
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
>> config.authentication.username | |
=> "[email protected]@" | |
>> config.authentication.password | |
=> "myhackproofpassword" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment