Class: Datadog::Core::Configuration::OptionDefinition::Builder
- Inherits:
-
Object
- Object
- Datadog::Core::Configuration::OptionDefinition::Builder
- Defined in:
- lib/datadog/core/configuration/option_definition.rb
Overview
Acts as DSL for building OptionDefinitions
Constant Summary collapse
- InvalidOptionError =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#helpers ⇒ Object
readonly
Returns the value of attribute helpers.
Instance Method Summary collapse
- #after_set(&block) ⇒ Object
-
#apply_options!(options = {}) ⇒ Object
For applying options for OptionDefinition.
- #default(value = nil, &block) ⇒ Object
- #default_proc(&block) ⇒ Object
-
#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, &block) ⇒ Object
-
#initialize(name, options = {}) {|_self| ... } ⇒ Builder
constructor
A new instance of Builder.
- #meta ⇒ Object
- #resetter(&block) ⇒ Object
- #setter(&block) ⇒ Object
- #to_definition ⇒ Object
- #type(value, nilable: false) ⇒ Object
Constructor Details
#initialize(name, options = {}) {|_self| ... } ⇒ Builder
Returns a new instance of Builder.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 51 def initialize(name, = {}) @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 = {} # 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.
48 49 50 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 48 def helpers @helpers end |
Instance Method Details
#after_set(&block) ⇒ Object
94 95 96 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 94 def after_set(&block) @after_set = block end |
#apply_options!(options = {}) ⇒ Object
For applying options for OptionDefinition
114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 114 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) 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 |
#default(value = nil, &block) ⇒ Object
82 83 84 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 82 def default(value = nil, &block) @default = block || value end |
#default_proc(&block) ⇒ Object
86 87 88 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 86 def default_proc(&block) @default_proc = block end |
#env(value) ⇒ Object
standard:disable Style/TrivialAccessors
72 73 74 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 72 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).
78 79 80 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 78 def env_parser(&block) @env_parser = block end |
#helper(name, *_args, &block) ⇒ Object
90 91 92 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 90 def helper(name, *_args, &block) @helpers[name] = block end |
#meta ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 132 def { default: @default, default_proc: @default_proc, env: @env, env_parser: @env_parser, after_set: @after_set, resetter: @resetter, setter: @setter, type: @type, type_options: } end |
#resetter(&block) ⇒ Object
98 99 100 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 98 def resetter(&block) @resetter = block end |
#setter(&block) ⇒ Object
102 103 104 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 102 def setter(&block) @setter = block end |
#to_definition ⇒ Object
128 129 130 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 128 def to_definition OptionDefinition.new(@name, ) end |
#type(value, nilable: false) ⇒ Object
106 107 108 109 110 111 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 106 def type(value, nilable: false) @type = value = {nilable: nilable} value end |