Class: Configurable
- Inherits:
-
Object
- Object
- Configurable
- Defined in:
- lib/app.rb
Overview
Provides configuration via superclass. Inherit from Configurable, and you have a handy little DSL/class for assigning/accessing your app settings.
class App < Configurable
config.launched_at = Time.now.utc
end
App.launched_at # => 2010-02-21 12:34:56 UTC
Configurable classes will warn you when you call undefined settings.
App.typo # => nil
warning: undefined setting `typo' for App:Class
If you don’t care about these warnings, just redefine the logger.
App.configure do
config.logger = Logger.new nil
end
Direct Known Subclasses
Defined Under Namespace
Classes: Plugin
Class Method Summary collapse
Class Method Details
.[](key) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/app.rb', line 34 def [](key) config.respond_to? key or logger.warn "warning: undefined setting `#{key}' for #{__name__}:Class" config.send key end |
.inspect ⇒ Object
41 42 43 |
# File 'lib/app.rb', line 41 def inspect config.inspect.sub config.class.name, __name__ end |
.logger ⇒ Object
45 46 47 48 49 50 |
# File 'lib/app.rb', line 45 def logger return config.logger if config.respond_to? :logger return @logger if defined? @logger @logger ||= Rails.logger if defined? Rails @logger ||= Logger.new STDERR end |