Skip to content

Instantly share code, notes, and snippets.

@spannerinworks
Created May 22, 2012 09: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 spannerinworks/2767931 to your computer and use it in GitHub Desktop.
Save spannerinworks/2767931 to your computer and use it in GitHub Desktop.
App Config
# ---------------------------
# 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