123456789_123456789_123456789_123456789_123456789_

Module: Mongo::Config::Options Private

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Extended In:
Defined in: lib/mongo/config/options.rb

Overview

Encapsulates logic for setting options.

Instance Method Summary

Instance Method Details

#defaultsHash

Get the defaults or initialize a new empty hash.

Returns:

  • (Hash)

    The default options.

[ GitHub ]

  
# File 'lib/mongo/config/options.rb', line 13

def defaults
  @defaults ||= {}
end

#option(name, options = {})

Define a configuration option with a default.

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.

[ GitHub ]

  
# File 'lib/mongo/config/options.rb', line 23

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

  class_eval do
    # log_level accessor is defined specially below
    define_method(name) do
      settings[name]
    end

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

    define_method("#{name}?") do
      !!send(name)
    end
  end
end

#resetHash

Reset the configuration options to the defaults.

Examples:

Reset the configuration options.

config.reset

Returns:

  • (Hash)

    The defaults.

[ GitHub ]

  
# File 'lib/mongo/config/options.rb', line 48

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.

[ GitHub ]

  
# File 'lib/mongo/config/options.rb', line 58

def settings
  @settings ||= {}
end