Class: Datadog::Core::Configuration::OptionDefinition::Builder
- Inherits:
-
Object
- Object
- Datadog::Core::Configuration::OptionDefinition::Builder
- Defined in:
- lib/datadog/core/configuration/option_definition.rb,
sig/datadog/core/configuration/option_definition.rbs
Overview
Acts as DSL for building OptionDefinitions
Instance Attribute Summary collapse
-
#helpers ⇒ Object
readonly
Returns the value of attribute helpers.
Instance Method Summary collapse
- #after_set(&block) ⇒ void
-
#apply_options!(options = {}) ⇒ Object
For applying options for OptionDefinition.
- #attributes ⇒ attributes
-
#default(value = nil, &block) ⇒ Object
can also be a class that includes Configuration::Base for new settings.
- #default_proc(&block) ⇒ void
-
#env(value) ⇒ Object
standard:disable Style/TrivialAccessors.
-
#env_parser(&block) ⇒ Object
Invoked when the option is first read, and #env is defined.
- #helper(name, *_args) {|arg0| ... } ⇒ void
-
#initialize(name, options = {}) {|_self| ... } ⇒ Builder
constructor
A new instance of Builder.
- #resetter(&block) ⇒ void
- #setter {|new_value, old_value| ... } ⇒ void
-
#skip_telemetry(value) ⇒ Object
This should only be set to true for options that are manually modified before being added to the telemetry payload in app_started.rb.
- #to_definition ⇒ OptionDefinition
- #type(value, nilable: false) ⇒ Symbol?
- #validate_options! ⇒ void
Constructor Details
#initialize(name, options = {}) {|_self| ... } ⇒ Builder
Returns a new instance of Builder.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 59 def initialize(name, = {}) @is_settings = .fetch(:is_settings, false) @env = nil @env_parser = nil @default = nil @default_proc = nil @helpers = {} @name = name.to_sym @after_set = nil @skip_telemetry = false @resetter = nil @setter = OptionDefinition::IDENTITY @type = nil @type_options = {} # 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.
56 57 58 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 56 def helpers @helpers end |
Instance Method Details
#after_set(&block) ⇒ void
This method returns an undefined value.
105 106 107 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 105 def after_set(&block) @after_set = block end |
#apply_options!(options = {}) ⇒ Object
For applying options for OptionDefinition
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 135 def ( = {}) return if .nil? || .empty? default([:default]) if .key?(:default) default_proc(&[:default_proc]) if .key?(:default_proc) env([:env]) if .key?(:env) env_parser(&[:env_parser]) if .key?(:env_parser) after_set(&[:after_set]) if .key?(:after_set) # Steep: https://github.com/soutaro/steep/issues/1979 skip_telemetry([:skip_telemetry]) if .key?(:skip_telemetry) # steep:ignore ArgumentTypeMismatch resetter(&[:resetter]) if .key?(:resetter) # Steep: https://github.com/soutaro/steep/issues/1979 setter(&[:setter]) if .key?(:setter) # steep:ignore BlockTypeMismatch type([:type], **([:type_options] || {})) if .key?(:type) end |
#attributes ⇒ attributes
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 155 def attributes { is_settings: @is_settings, default: @default, default_proc: @default_proc, env: @env, env_parser: @env_parser, after_set: @after_set, skip_telemetry: @skip_telemetry, resetter: @resetter, setter: @setter, type: @type, type_options: @type_options } end |
#default(value = nil, &block) ⇒ Object
can also be a class that includes Configuration::Base for new settings
100 101 102 |
# File 'sig/datadog/core/configuration/option_definition.rbs', line 100 def default(value = nil, &block) @default = block || value end |
#default_proc(&block) ⇒ void
This method returns an undefined value.
97 98 99 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 97 def default_proc(&block) @default_proc = block end |
#env(value) ⇒ Object
standard:disable Style/TrivialAccessors
83 84 85 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 83 def env(value) # standard:disable Style/TrivialAccessors @env = value end |
#env_parser(&block) ⇒ Object
Invoked when the option is first read, and #env is defined. The block provided is only invoked if the environment variable is present (not-nil).
89 90 91 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 89 def env_parser(&block) @env_parser = block end |
#helper(name, *_args) {|arg0| ... } ⇒ void
This method returns an undefined value.
101 102 103 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 101 def helper(name, *_args, &block) @helpers[name] = block end |
#resetter(&block) ⇒ void
This method returns an undefined value.
119 120 121 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 119 def resetter(&block) @resetter = block end |
#setter {|new_value, old_value| ... } ⇒ void
This method returns an undefined value.
123 124 125 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 123 def setter(&block) @setter = block end |
#skip_telemetry(value) ⇒ Object
This should only be set to true for options that are manually modified
before being added to the telemetry payload in app_started.rb.
E.g. telemetry is skipped for tracing.writer_options, but in app_started.rb,
we send two separate entries for the buffer_size and flush_interval values.
Standard: We want to keep this method as skip_telemetry(value),
not skip_telemetry = value, so attr_writer is not used.
115 116 117 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 115 def skip_telemetry(value) # standard:disable Style/TrivialAccessors @skip_telemetry = value end |
#to_definition ⇒ OptionDefinition
151 152 153 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 151 def to_definition OptionDefinition.new(@name, attributes) end |
#type(value, nilable: false) ⇒ Symbol?
127 128 129 130 131 132 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 127 def type(value, nilable: false) @type = value @type_options = {nilable: nilable} value end |
#validate_options! ⇒ void
This method returns an undefined value.
174 175 176 177 178 179 180 181 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 174 def if !@default.nil? && @default_proc raise InvalidOptionError, 'Using `default` and `default_proc` is not allowed. Please use one or the other.' \ 'If you want to store a block as the default value use `default_proc`' \ ' otherwise use `default`' end end |