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



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

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



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

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

  class_eval "    def \#{name}                                               # def endpoint\n      settings[\#{name.inspect}]                               #   settings[\"endpoint\"]\n    end                                                       # end\n\n    def \#{name}=(value)                                       # def endpoint=(value)\n      settings[\#{name.inspect}] = value                       #   settings[\"endpoint\"] = value\n    end                                                       # end\n\n    def \#{name}?                                              # def endpoint?\n      \#{name}                                                 #   endpoint\n    end                                                       # end\n\n    def reset_\#{name}                                         # def reset_endpoint\n      settings[\#{name.inspect}] = defaults[\#{name.inspect}]   #   settings[\"endpoint\"] = defaults[\"endpoint\"]\n    end                                                       # end\n  RUBY\nend\n", __FILE__, __LINE__ + 1

#resetHash

Reset the configuration options to the defaults.

Examples:

Reset the configuration options.

config.reset

Returns:

  • (Hash)

    The defaults.

Since:

  • 0.2.0



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

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



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

def settings
  @settings ||= {}
end