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
- #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.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ddtrace/configuration/option_definition.rb', line 41 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.
38 39 40 |
# File 'lib/ddtrace/configuration/option_definition.rb', line 38 def helpers @helpers end |
Instance Method Details
#apply_options!(options = {}) ⇒ Object
For applying options for OptionDefinition
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/ddtrace/configuration/option_definition.rb', line 92 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
63 64 65 |
# File 'lib/ddtrace/configuration/option_definition.rb', line 63 def default(value = nil, &block) @default = block || value end |
#delegate_to(&block) ⇒ Object
67 68 69 |
# File 'lib/ddtrace/configuration/option_definition.rb', line 67 def delegate_to(&block) @delegate_to = block end |
#depends_on(*values) ⇒ Object
59 60 61 |
# File 'lib/ddtrace/configuration/option_definition.rb', line 59 def depends_on(*values) @depends_on = values.flatten end |
#helper(name, *_args, &block) ⇒ Object
71 72 73 |
# File 'lib/ddtrace/configuration/option_definition.rb', line 71 def helper(name, *_args, &block) @helpers[name] = block end |
#lazy(value = true) ⇒ Object
75 76 77 |
# File 'lib/ddtrace/configuration/option_definition.rb', line 75 def lazy(value = true) @lazy = value end |
#meta ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/ddtrace/configuration/option_definition.rb', line 108 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
79 80 81 |
# File 'lib/ddtrace/configuration/option_definition.rb', line 79 def on_set(&block) @on_set = block end |
#resetter(&block) ⇒ Object
83 84 85 |
# File 'lib/ddtrace/configuration/option_definition.rb', line 83 def resetter(&block) @resetter = block end |
#setter(&block) ⇒ Object
87 88 89 |
# File 'lib/ddtrace/configuration/option_definition.rb', line 87 def setter(&block) @setter = block end |
#to_definition ⇒ Object
104 105 106 |
# File 'lib/ddtrace/configuration/option_definition.rb', line 104 def to_definition OptionDefinition.new(@name, ) end |