Class: Datadog::Configuration::Option

Inherits:
Object
  • Object
show all
Defined in:
lib/ddtrace/configuration/option.rb

Overview

Represents an instance of an integration configuration option

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(definition, context) ⇒ Option

Returns a new instance of Option.



8
9
10
11
12
13
# File 'lib/ddtrace/configuration/option.rb', line 8

def initialize(definition, context)
  @definition = definition
  @context = context
  @value = nil
  @is_set = false
end

Instance Attribute Details

#definitionObject (readonly)

Returns the value of attribute definition.



5
6
7
# File 'lib/ddtrace/configuration/option.rb', line 5

def definition
  @definition
end

Instance Method Details

#getObject



22
23
24
25
26
27
28
29
30
# File 'lib/ddtrace/configuration/option.rb', line 22

def get
  if @is_set
    @value
  elsif definition.delegate_to
    context_eval(&definition.delegate_to)
  else
    set(definition.default_value)
  end
end

#resetObject



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ddtrace/configuration/option.rb', line 32

def reset
  @value = if definition.resetter
             # Don't change @is_set to false; custom resetters are
             # responsible for changing @value back to a good state.
             # Setting @is_set = false would cause a default to be applied.
             context_exec(@value, &definition.resetter)
           else
             @is_set = false
             nil
           end
end

#set(value) ⇒ Object



15
16
17
18
19
20
# File 'lib/ddtrace/configuration/option.rb', line 15

def set(value)
  (@value = context_exec(value, &definition.setter)).tap do |v|
    @is_set = true
    context_exec(v, &definition.on_set) if definition.on_set
  end
end