Module: Datadog::Core::Configuration::Options::InstanceMethods

Defined in:
lib/datadog/core/configuration/options.rb,
sig/datadog/core/configuration/options.rbs

Overview

Instance behavior for a configuration object with options

Instance Method Summary collapse

Instance Method Details

#assert_valid_option!(name) ⇒ void

This method returns an undefined value.

Parameters:

  • name (Symbol)

Raises:

  • (InvalidOptionError)


161
162
163
# File 'lib/datadog/core/configuration/options.rb', line 161

def assert_valid_option!(name)
  raise(InvalidOptionError, "#{self.class.name} doesn't define the option: #{name}") unless option_defined?(name)
end

#get_option(name) ⇒ Object



119
120
121
# File 'lib/datadog/core/configuration/options.rb', line 119

def get_option(name)
  resolve_option(name).get
end

#option_defined?(name) ⇒ Boolean

Returns:

  • (Boolean)


128
129
130
# File 'lib/datadog/core/configuration/options.rb', line 128

def option_defined?(name)
  self.class.options.key?(name)
end

#optionsObject



103
104
105
# File 'lib/datadog/core/configuration/options.rb', line 103

def options
  @options ||= {}
end

#options_hashObject



138
139
140
141
142
# File 'lib/datadog/core/configuration/options.rb', line 138

def options_hash
  self.class.options.merge(options).each_with_object({}) do |(key, _), hash|
    hash[key] = get_option(key)
  end
end

#reset_option(name) ⇒ Object



123
124
125
126
# File 'lib/datadog/core/configuration/options.rb', line 123

def reset_option(name)
  assert_valid_option!(name)
  options[name].reset if options.key?(name)
end

#reset_options!Object



144
145
146
# File 'lib/datadog/core/configuration/options.rb', line 144

def reset_options!
  options.each_value(&:reset)
end

#resolve_option(name) ⇒ Object

Ensure option DSL is loaded



151
152
153
154
155
156
157
158
159
# File 'lib/datadog/core/configuration/options.rb', line 151

def resolve_option(name)
  option = options[name]
  return option if option

  assert_valid_option!(name)
  definition = self.class.options[name]
  # @type self: Configuration::Options::_Settings
  options[name] = definition.build(self)
end

#set_option(name, value, precedence: Configuration::Option::Precedence::PROGRAMMATIC) ⇒ Object



107
108
109
110
111
112
113
# File 'lib/datadog/core/configuration/options.rb', line 107

def set_option(name, value, precedence: Configuration::Option::Precedence::PROGRAMMATIC)
  option = resolve_option(name)
  # Populate lower-precedence values so telemetry and `unset` can
  # still observe the fallback chain after a first programmatic set.
  option.get
  option.set(value, precedence: precedence)
end

#unset_option(name, precedence: Configuration::Option::Precedence::PROGRAMMATIC) ⇒ Object



115
116
117
# File 'lib/datadog/core/configuration/options.rb', line 115

def unset_option(name, precedence: Configuration::Option::Precedence::PROGRAMMATIC)
  resolve_option(name).unset(precedence)
end

#using_default?(name) ⇒ Object

Is this option's value the default fallback value?



133
134
135
136
# File 'lib/datadog/core/configuration/options.rb', line 133

def using_default?(name)
  get_option(name) # Resolve value check if environment variable overwrote the default
  options[name].default_precedence?
end