Class: Datadog::Core::Configuration::OptionDefinition::Builder
- Inherits:
-
Object
- Object
- Datadog::Core::Configuration::OptionDefinition::Builder
show all
- Defined in:
- lib/datadog/core/configuration/option_definition.rb
Overview
Acts as DSL for building OptionDefinitions
Defined Under Namespace
Classes: InvalidOptionError
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name, options = {}) {|_self| ... } ⇒ Builder
Returns a new instance of Builder.
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/datadog/core/configuration/option_definition.rb', line 52
def initialize(name, options = {})
@env = nil
@deprecated_env = nil
@env_parser = nil
@default = nil
@default_proc = nil
@helpers = {}
@name = name.to_sym
@after_set = nil
@resetter = nil
@setter = OptionDefinition::IDENTITY
@type = nil
@type_options = {}
apply_options!(options)
yield(self) if block_given?
validate_options!
end
|
Instance Attribute Details
#helpers ⇒ Object
Returns the value of attribute helpers.
49
50
51
|
# File 'lib/datadog/core/configuration/option_definition.rb', line 49
def helpers
@helpers
end
|
Instance Method Details
#after_set(&block) ⇒ Object
108
109
110
|
# File 'lib/datadog/core/configuration/option_definition.rb', line 108
def after_set(&block)
@after_set = block
end
|
#apply_options!(options = {}) ⇒ Object
For applying options for OptionDefinition
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
# File 'lib/datadog/core/configuration/option_definition.rb', line 128
def apply_options!(options = {})
return if options.nil? || options.empty?
default(options[:default]) if options.key?(:default)
default_proc(&options[:default_proc]) if options.key?(:default_proc)
env(options[:env]) if options.key?(:env)
deprecated_env(options[:deprecated_env]) if options.key?(:deprecated_env)
env_parser(&options[:env_parser]) if options.key?(:env_parser)
lazy(options[:lazy]) if options.key?(:lazy)
after_set(&options[:after_set]) if options.key?(:after_set)
resetter(&options[:resetter]) if options.key?(:resetter)
setter(&options[:setter]) if options.key?(:setter)
type(options[:type], **(options[:type_options] || {})) if options.key?(:type)
end
|
#default(value = nil, &block) ⇒ Object
86
87
88
|
# File 'lib/datadog/core/configuration/option_definition.rb', line 86
def default(value = nil, &block)
@default = block || value
end
|
#default_proc(&block) ⇒ Object
90
91
92
|
# File 'lib/datadog/core/configuration/option_definition.rb', line 90
def default_proc(&block)
@default_proc = block
end
|
#deprecated_env(value) ⇒ Object
78
79
80
|
# File 'lib/datadog/core/configuration/option_definition.rb', line 78
def deprecated_env(value)
@deprecated_env = value
end
|
#env(value) ⇒ Object
74
75
76
|
# File 'lib/datadog/core/configuration/option_definition.rb', line 74
def env(value)
@env = value
end
|
#env_parser(&block) ⇒ Object
82
83
84
|
# File 'lib/datadog/core/configuration/option_definition.rb', line 82
def env_parser(&block)
@env_parser = block
end
|
#helper(name, *_args, &block) ⇒ Object
94
95
96
|
# File 'lib/datadog/core/configuration/option_definition.rb', line 94
def helper(name, *_args, &block)
@helpers[name] = block
end
|
#lazy(_value = true) ⇒ Object
98
99
100
101
102
103
104
105
106
|
# File 'lib/datadog/core/configuration/option_definition.rb', line 98
def lazy(_value = true)
Datadog::Core.log_deprecation do
'Defining an option as lazy is deprecated for removal. Options now always behave as lazy. '\
"Please remove all references to the lazy setting.\n"\
'Non-lazy options that were previously stored as blocks are no longer supported. '\
'If you used this feature, please let us know by opening an issue on: '\
'https://github.com/datadog/dd-trace-rb/issues/new so we can better understand and support your use case.'
end
end
|
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
# File 'lib/datadog/core/configuration/option_definition.rb', line 147
def meta
{
default: @default,
default_proc: @default_proc,
env: @env,
deprecated_env: @deprecated_env,
env_parser: @env_parser,
after_set: @after_set,
resetter: @resetter,
setter: @setter,
type: @type,
type_options: @type_options
}
end
|
#resetter(&block) ⇒ Object
112
113
114
|
# File 'lib/datadog/core/configuration/option_definition.rb', line 112
def resetter(&block)
@resetter = block
end
|
#setter(&block) ⇒ Object
116
117
118
|
# File 'lib/datadog/core/configuration/option_definition.rb', line 116
def setter(&block)
@setter = block
end
|
#to_definition ⇒ Object
143
144
145
|
# File 'lib/datadog/core/configuration/option_definition.rb', line 143
def to_definition
OptionDefinition.new(@name, meta)
end
|
#type(value, nilable: false) ⇒ Object
120
121
122
123
124
125
|
# File 'lib/datadog/core/configuration/option_definition.rb', line 120
def type(value, nilable: false)
@type = value
@type_options = { nilable: nilable }
value
end
|