Method: Datadog::Core::Configuration::Option#unset

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

#unset(precedence) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/datadog/core/configuration/option.rb', line 100

def unset(precedence)
  @value_per_precedence[precedence] = UNSET

  # If we are unsetting the currently active value, we have to restore
  # a lower precedence one...
  if precedence == @precedence_set
    # Find a lower precedence value that is already set.
    Precedence::LIST.each do |p|
      # DEV: This search can be optimized, but the list is small, and unset is
      # DEV: only called from direct user interaction in the Datadog UI.
      next unless p < precedence

      # Look for value that is set.
      # The hash `@value_per_precedence` has a custom default value of `UNSET`.
      if (value = @value_per_precedence[p]) != UNSET
        internal_set(value, p, nil)
        return nil
      end
    end

    # If no value is left to fall back on, reset this option
    reset
  end

  # ... otherwise, we are either unsetting a higher precedence value that is not
  # yet set, thus there's nothing to do; or we are unsetting a lower precedence
  # value, which also does not change the current value.
end