Module: Cloudsearchable::Config::Options::ClassMethods

Defined in:
lib/cloudsearchable/config/options.rb

Instance Method Summary collapse

Instance Method Details

#defaultsObject

Get the defaults or initialize a new empty hash.



12
13
14
# File 'lib/cloudsearchable/config/options.rb', line 12

def defaults
  @defaults ||= {}
end

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

Define a configuration option with a default. Example usage:

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


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cloudsearchable/config/options.rb', line 28

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

  define_method name do
    settings[name]
  end

  define_method "#{name}=" do |value|
    settings[name] = value
  end

  define_method "#{name}?" do
    !!settings[name]
  end

  define_method "reset_#{name}" do
    settings[name] = defaults[name]
  end
end

#resetObject

Reset the configuration options to the defaults.



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

def reset
  settings.replace(defaults)
end

#settingsObject

Get the settings or initialize a new empty hash.



22
23
24
# File 'lib/cloudsearchable/config/options.rb', line 22

def settings
  @settings ||= {}
end