Class: ActiveConfiguration::Base

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeBase

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
  @options = HashWithIndifferentAccess.new
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



9
10
11
# File 'lib/active_configuration/base.rb', line 9

def options
  @options
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.

Parameters:

  • key (Symbol)

    the key for this option and settings against this option.

  • block (Proc)

    what should be evaluated against the 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)
  @options[key.to_sym] = opt
end