Module: Mongo::Config::Options Private

Included in:
Mongo::Config
Defined in:
build/ruby-driver-v2.18/lib/mongo/config/options.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Encapsulates logic for setting options.

Instance Method Summary collapse

Instance Method Details

#defaultsHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get the defaults or initialize a new empty hash.

Returns:

  • (Hash)

    The default options.



12
13
14
# File 'build/ruby-driver-v2.18/lib/mongo/config/options.rb', line 12

def defaults
  @defaults ||= {}
end

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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'build/ruby-driver-v2.18/lib/mongo/config/options.rb', line 22

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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Reset the configuration options to the defaults.

Examples:

Reset the configuration options.

config.reset

Returns:

  • (Hash)

    The defaults.



47
48
49
# File 'build/ruby-driver-v2.18/lib/mongo/config/options.rb', line 47

def reset
  settings.replace(defaults)
end

#settingsHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get the settings or initialize a new empty hash.

Examples:

Get the settings.

options.settings

Returns:

  • (Hash)

    The setting options.



57
58
59
# File 'build/ruby-driver-v2.18/lib/mongo/config/options.rb', line 57

def settings
  @settings ||= {}
end