Module: Dynamoid::Config::Options

Included in:
Dynamoid::Config
Defined in:
lib/dynamoid/config/options.rb

Overview

Encapsulates logic for setting options.

Instance Method Summary collapse

Instance Method Details

#defaultsHash

Get the defaults or initialize a new empty hash.

Examples:

Get the defaults.

options.defaults

Returns:

  • (Hash)

    The default options.

Since:

  • 0.2.0



16
17
18
# File 'lib/dynamoid/config/options.rb', line 16

def defaults
  @defaults ||= {}
end

#option(name, options = {}) ⇒ Object

Define a configuration option with a default.

Examples:

Define the option.

Options.option(:persist_in_safe_mode, :default => false)

Parameters:

  • name (Symbol)

    The name of the configuration option.

  • options (Hash) (defaults to: {})

    Extras for the option.

Options Hash (options):

  • :default (Object)

    The default value.

Since:

  • 0.2.0



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/dynamoid/config/options.rb', line 31

def option(name, options = {})
  defaults[name] = settings[name] = options[:default]

  class_eval <<-RUBY
    def #{name}
      settings[#{name.inspect}]
    end

    def #{name}=(value)
      settings[#{name.inspect}] = value
    end

    def #{name}?
      #{name}
    end
    
    def reset_#{name}
      settings[#{name.inspect}] = defaults[#{name.inspect}]
    end
  RUBY
end

#resetHash

Reset the configuration options to the defaults.

Examples:

Reset the configuration options.

config.reset

Returns:

  • (Hash)

    The defaults.

Since:

  • 0.2.0



61
62
63
# File 'lib/dynamoid/config/options.rb', line 61

def reset
  settings.replace(defaults)
end

#settingsHash

Get the settings or initialize a new empty hash.

Examples:

Get the settings.

options.settings

Returns:

  • (Hash)

    The setting options.

Since:

  • 0.2.0



73
74
75
# File 'lib/dynamoid/config/options.rb', line 73

def settings
  @settings ||= {}
end