Class: Datadog::Configuration::Option
- Inherits:
-
Object
- Object
- Datadog::Configuration::Option
- Defined in:
- lib/ddtrace/configuration/option.rb
Overview
Represents an instance of an integration configuration option
Instance Attribute Summary collapse
-
#definition ⇒ Object
readonly
Returns the value of attribute definition.
Instance Method Summary collapse
- #default_value ⇒ Object
- #get ⇒ Object
-
#initialize(definition, context) ⇒ Option
constructor
A new instance of Option.
- #reset ⇒ Object
- #set(value) ⇒ Object
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
#definition ⇒ Object (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
#default_value ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/ddtrace/configuration/option.rb', line 45 def default_value if definition.lazy context_eval(&definition.default) else definition.default end end |
#get ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/ddtrace/configuration/option.rb', line 23 def get if @is_set @value elsif definition.delegate_to context_eval(&definition.delegate_to) else set(default_value) end end |
#reset ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ddtrace/configuration/option.rb', line 33 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 21 |
# File 'lib/ddtrace/configuration/option.rb', line 15 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 |