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.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 50 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 @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.
47 48 49 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 47 def helpers @helpers end |
Instance Method Details
#after_set(&block) ⇒ Object
93 94 95 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 93 def after_set(&block) @after_set = block end |
#apply_options!(options = {}) ⇒ Object
For applying options for OptionDefinition
113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 113 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) setter(&[:setter]) if .key?(:setter) type([:type], **([:type_options] || {})) if .key?(:type) end |
#default(value = nil, &block) ⇒ Object
81 82 83 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 81 def default(value = nil, &block) @default = block || value end |
#default_proc(&block) ⇒ Object
85 86 87 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 85 def default_proc(&block) @default_proc = block end |
#env(value) ⇒ Object
standard:disable Style/TrivialAccessors
71 72 73 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 71 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).
77 78 79 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 77 def env_parser(&block) @env_parser = block end |
#helper(name, *_args, &block) ⇒ Object
89 90 91 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 89 def helper(name, *_args, &block) @helpers[name] = block end |
#meta ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 130 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: @type_options } end |
#resetter(&block) ⇒ Object
97 98 99 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 97 def resetter(&block) @resetter = block end |
#setter(&block) ⇒ Object
101 102 103 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 101 def setter(&block) @setter = block end |
#to_definition ⇒ Object
126 127 128 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 126 def to_definition OptionDefinition.new(@name, ) end |
#type(value, nilable: false) ⇒ Object
105 106 107 108 109 110 |
# File 'lib/datadog/core/configuration/option_definition.rb', line 105 def type(value, nilable: false) @type = value @type_options = {nilable: nilable} value end |