Class: Datadog::Configuration::OptionDefinition::Builder
- Inherits:
-
Object
- Object
- Datadog::Configuration::OptionDefinition::Builder
- Defined in:
- lib/ddtrace/configuration/option_definition.rb
Overview
Acts as DSL for building OptionDefinitions
Instance Attribute Summary collapse
-
#helpers ⇒ Object
readonly
Returns the value of attribute helpers.
Instance Method Summary collapse
-
#apply_options!(options = {}) ⇒ Object
For applying options for OptionDefinition.
- #default(value = nil, &block) ⇒ Object
- #delegate_to(&block) ⇒ Object
- #depends_on(*values) ⇒ Object
- #helper(name, *_args, &block) ⇒ Object
-
#initialize(name, options = {}) {|_self| ... } ⇒ Builder
constructor
A new instance of Builder.
-
#lazy(value = true) ⇒ Object
rubocop:disable Style/TrivialAccessors (Rubocop erroneously thinks #lazy == #lazy= ).
- #meta ⇒ Object
- #on_set(&block) ⇒ Object
- #resetter(&block) ⇒ Object
- #setter(&block) ⇒ Object
- #to_definition ⇒ Object
Constructor Details
#initialize(name, options = {}) {|_self| ... } ⇒ Builder
Returns a new instance of Builder.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ddtrace/configuration/option_definition.rb', line 44 def initialize(name, = {}) @default = nil @delegate_to = nil @depends_on = [] @helpers = {} @lazy = false @name = name.to_sym @on_set = nil @resetter = nil @setter = OptionDefinition::IDENTITY # If options were supplied, apply them. () # Apply block if given. yield(self) if block_given? end |
Instance Attribute Details
#helpers ⇒ Object (readonly)
Returns the value of attribute helpers.
41 42 43 |
# File 'lib/ddtrace/configuration/option_definition.rb', line 41 def helpers @helpers end |
Instance Method Details
#apply_options!(options = {}) ⇒ Object
For applying options for OptionDefinition
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/ddtrace/configuration/option_definition.rb', line 97 def ( = {}) return if .nil? || .empty? default([:default]) if .key?(:default) delegate_to(&[:delegate_to]) if .key?(:delegate_to) depends_on(*[:depends_on]) if .key?(:depends_on) lazy([:lazy]) if .key?(:lazy) on_set(&[:on_set]) if .key?(:on_set) resetter(&[:resetter]) if .key?(:resetter) setter(&[:setter]) if .key?(:setter) end |
#default(value = nil, &block) ⇒ Object
66 67 68 |
# File 'lib/ddtrace/configuration/option_definition.rb', line 66 def default(value = nil, &block) @default = block_given? ? block : value end |
#delegate_to(&block) ⇒ Object
70 71 72 |
# File 'lib/ddtrace/configuration/option_definition.rb', line 70 def delegate_to(&block) @delegate_to = block end |
#depends_on(*values) ⇒ Object
62 63 64 |
# File 'lib/ddtrace/configuration/option_definition.rb', line 62 def depends_on(*values) @depends_on = values.flatten end |
#helper(name, *_args, &block) ⇒ Object
74 75 76 |
# File 'lib/ddtrace/configuration/option_definition.rb', line 74 def helper(name, *_args, &block) @helpers[name] = block end |
#lazy(value = true) ⇒ Object
rubocop:disable Style/TrivialAccessors (Rubocop erroneously thinks #lazy == #lazy= )
80 81 82 |
# File 'lib/ddtrace/configuration/option_definition.rb', line 80 def lazy(value = true) @lazy = value end |
#meta ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/ddtrace/configuration/option_definition.rb', line 113 def { default: @default, delegate_to: @delegate_to, depends_on: @depends_on, lazy: @lazy, on_set: @on_set, resetter: @resetter, setter: @setter } end |
#on_set(&block) ⇒ Object
84 85 86 |
# File 'lib/ddtrace/configuration/option_definition.rb', line 84 def on_set(&block) @on_set = block end |
#resetter(&block) ⇒ Object
88 89 90 |
# File 'lib/ddtrace/configuration/option_definition.rb', line 88 def resetter(&block) @resetter = block end |
#setter(&block) ⇒ Object
92 93 94 |
# File 'lib/ddtrace/configuration/option_definition.rb', line 92 def setter(&block) @setter = block end |
#to_definition ⇒ Object
109 110 111 |
# File 'lib/ddtrace/configuration/option_definition.rb', line 109 def to_definition OptionDefinition.new(@name, ) end |