Class: Datadog::Core::Configuration::Option

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/core/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.



12
13
14
15
16
17
# File 'lib/datadog/core/configuration/option.rb', line 12

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.



9
10
11
# File 'lib/datadog/core/configuration/option.rb', line 9

def definition
  @definition
end

Instance Method Details

#default_valueObject



49
50
51
52
53
54
55
# File 'lib/datadog/core/configuration/option.rb', line 49

def default_value
  if definition.lazy
    context_eval(&definition.default)
  else
    definition.default
  end
end

#getObject



27
28
29
30
31
32
33
34
35
# File 'lib/datadog/core/configuration/option.rb', line 27

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

#resetObject



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/datadog/core/configuration/option.rb', line 37

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



19
20
21
22
23
24
25
# File 'lib/datadog/core/configuration/option.rb', line 19

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