Skip to content

Instantly share code, notes, and snippets.

@stephencelis
Created January 19, 2010 03:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stephencelis/280650 to your computer and use it in GitHub Desktop.
Save stephencelis/280650 to your computer and use it in GitHub Desktop.
App update
# Define application-level configuration using a simple DSL.
#
# class App < Configuration
# config.key = "value"
# config.lazy = lambda { |load| load }
# end
#
# App.key # => "value"
# App.key? # => true
# App.lazy("load") # => "load"
# App.lazy?(nil) # => false
#
# Override by Rails environment.
#
# # config/app/development.rb
# config.key = "devalue"
#
# App.key # => "devalue"
class Configuration
autoload :OpenStruct, "ostruct"
class << self
def [](key)
config.send key
end
def inspect
config.inspect.sub config.class.name, name
end
private
def config
@config ||= OpenStruct.new
end
def method_missing(method, *args)
super if (key = method.to_s).end_with?("=")
boolean = key.chomp!("?")
value = self[key]
value = value.call(*args) if value.respond_to?(:call)
boolean ? !!value : value
end
def inherited(subclass)
return unless defined? Rails
config = "#{Rails.root}/config/#{name.underscore}/#{Rails.env}.rb"
if File.exist?(config)
eval File.read(config), binding, __FILE__, __LINE__
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment