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
98
99
100
|
# File 'lib/datadog/core/configuration/option_definition.rb', line 98
def after_set(&block)
@after_set = block
end
|
#apply_options!(options = {}) ⇒ Object
For applying options for OptionDefinition
118
119
120
121
122
123
124
125
126
127
128
129
130
|
# File 'lib/datadog/core/configuration/option_definition.rb', line 118
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)
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
|
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
# File 'lib/datadog/core/configuration/option_definition.rb', line 136
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
102
103
104
|
# File 'lib/datadog/core/configuration/option_definition.rb', line 102
def resetter(&block)
@resetter = block
end
|
#setter(&block) ⇒ Object
106
107
108
|
# File 'lib/datadog/core/configuration/option_definition.rb', line 106
def setter(&block)
@setter = block
end
|
#to_definition ⇒ Object
132
133
134
|
# File 'lib/datadog/core/configuration/option_definition.rb', line 132
def to_definition
OptionDefinition.new(@name, meta)
end
|
#type(value, nilable: false) ⇒ Object
110
111
112
113
114
115
|
# File 'lib/datadog/core/configuration/option_definition.rb', line 110
def type(value, nilable: false)
@type = value
@type_options = { nilable: nilable }
value
end
|