Module: Mongo::Config::Options Private

Included in:
Mongo::Config
Defined in:
build/ruby-driver-v2.19/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.



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

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.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'build/ruby-driver-v2.19/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

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.



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

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.



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

def settings
  @settings ||= {}
end