Module: Datadog::Core::Configuration::Base::InstanceMethods

Defined in:
lib/datadog/core/configuration/base.rb

Overview

Instance methods for configuration

Instance Method Summary collapse

Instance Method Details

#configure(opts = {}) {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/datadog/core/configuration/base.rb', line 59

def configure(opts = {})
  # Sort the options in preference of dependency order first
  ordering = self.class.options.dependency_order
  sorted_opts = opts.sort_by do |name, _value|
    ordering.index(name) || (ordering.length + 1)
  end.to_h

  # Apply options in sort order
  sorted_opts.each do |name, value|
    if respond_to?("#{name}=")
      send("#{name}=", value)
    elsif option_defined?(name)
      set_option(name, value)
    end
  end

  # Apply any additional settings from block
  yield(self) if block_given?
end

#dig(*options) ⇒ Object

Retrieves a nested option from a list of symbols

Raises:

  • (ArgumentError)


84
85
86
87
88
89
90
# File 'lib/datadog/core/configuration/base.rb', line 84

def dig(*options)
  raise ArgumentError, 'expected at least one option' if options.empty?

  options.inject(self) do |receiver, option|
    receiver.send(option)
  end
end

#initialize(options = {}) ⇒ Object



55
56
57
# File 'lib/datadog/core/configuration/base.rb', line 55

def initialize(options = {})
  configure(options) unless options.empty?
end

#reset!Object



92
93
94
# File 'lib/datadog/core/configuration/base.rb', line 92

def reset!
  reset_options!
end

#to_hObject



79
80
81
# File 'lib/datadog/core/configuration/base.rb', line 79

def to_h
  options_hash
end