Created
May 22, 2012 09:49
-
-
Save spannerinworks/2767931 to your computer and use it in GitHub Desktop.
App Config
This file contains 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
# --------------------------- | |
# In config/application.yml : | |
# | |
# development: | |
# blah: "foo" | |
# test: | |
# blah: "bar" | |
# | |
# --------------------------- | |
# In app: | |
# | |
# AppConfig.blah | |
# | |
# | |
class AppConfig | |
class << self | |
@@config = nil | |
protected | |
def config | |
@@config ||= YAML.load_file(File.join(RAILS_ROOT, %w(config application.yml)))[RAILS_ENV] | |
end | |
public | |
def has_setting?(name) | |
self.config.has_key?(name.to_s) | |
end | |
def method_missing(name, *args) | |
if has_setting?(name.to_s) | |
self.config[name.to_s] | |
else | |
super | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment