Class: ActiveConfiguration::Base
- Inherits:
-
Object
- Object
- ActiveConfiguration::Base
- Defined in:
- lib/active_configuration/base.rb
Overview
Holds a set of configuration details. An instance of this object is created when the #configure block is used on an ActiveRecord model. For more details see ActiveRecord::Configuration#configure.
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize ⇒ Base
constructor
Initializes an empty options hash to store ActiveConfiguration::Option instances containing configuration details.
-
#option(key, &block) ⇒ Object
Creates and accepts the configuration details for an Option.
Constructor Details
#initialize ⇒ Base
Initializes an empty options hash to store ActiveConfiguration::Option instances containing configuration details.
13 14 15 |
# File 'lib/active_configuration/base.rb', line 13 def initialize = HashWithIndifferentAccess.new end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
9 10 11 |
# File 'lib/active_configuration/base.rb', line 9 def end |
Instance Method Details
#option(key, &block) ⇒ Object
Creates and accepts the configuration details for an Option.
An example of setting an option with a block:
option :sort do
default 'alphabetical'
restrict 'alphabetical', 'manual'
end
Here, the #option method is called and passed the key of :sort and then the the block that follows. The block given to #option is then evaluated against a new instance of ActiveConfiguration::Option.
32 33 34 35 36 |
# File 'lib/active_configuration/base.rb', line 32 def option(key, &block) opt = Option.new(key) opt.instance_eval(&block) [key.to_sym] = opt end |