Class: Datadog::Statsd::Schema::TagDefinition
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- Datadog::Statsd::Schema::TagDefinition
- Defined in:
- lib/datadog/statsd/schema/tag_definition.rb
Overview
Represents a tag definition within a schema namespace Defines validation rules, allowed values, transformations, and type constraints for tags
Defined Under Namespace
Modules: Types
Instance Method Summary collapse
-
#allows_value?(value) ⇒ Boolean
Check if a value is allowed for this tag according to the values constraint.
-
#name ⇒ Symbol
The tag name as a symbol.
-
#namespace ⇒ Symbol?
The namespace this tag belongs to.
-
#transform ⇒ Array<Symbol>
Array of transformation functions to apply to values.
-
#transform_value(value, transformers = {}) ⇒ Object
Apply transformations to a value using the provided transformer functions.
-
#type ⇒ Symbol
The expected data type for tag values.
-
#valid_value?(value, transformers = {}) ⇒ Boolean
Validate a value using type checking, transformations, and custom validation.
-
#validate ⇒ Proc?
Custom validation procedure for tag values.
-
#values ⇒ Array, ...
Allowed values for this tag (can be Array, Regexp, Proc, or single value).
Instance Method Details
#allows_value?(value) ⇒ Boolean
Check if a value is allowed for this tag according to the values constraint
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/datadog/statsd/schema/tag_definition.rb', line 65 def allows_value?(value) return true if values.nil? # No restrictions case values when Array values.include?(value) || values.include?(value.to_s) || values.include?(value.to_sym) when Regexp values.match?(value.to_s) when Proc values.call(value) else values == value end end |
#name ⇒ Symbol
The tag name as a symbol
36 |
# File 'lib/datadog/statsd/schema/tag_definition.rb', line 36 attribute :name, Types::Strict::Symbol |
#namespace ⇒ Symbol?
The namespace this tag belongs to
56 |
# File 'lib/datadog/statsd/schema/tag_definition.rb', line 56 attribute :namespace, Types::Strict::Symbol.optional.default(nil) |
#transform ⇒ Array<Symbol>
Array of transformation functions to apply to values
48 |
# File 'lib/datadog/statsd/schema/tag_definition.rb', line 48 attribute :transform, Types::Array.of(Types::Symbol).default([].freeze) |
#transform_value(value, transformers = {}) ⇒ Object
Apply transformations to a value using the provided transformer functions
88 89 90 91 92 93 94 95 |
# File 'lib/datadog/statsd/schema/tag_definition.rb', line 88 def transform_value(value, transformers = {}) return value if transform.empty? transform.reduce(value) do |val, transformer_name| transformer = transformers[transformer_name] transformer ? transformer.call(val) : val end end |
#type ⇒ Symbol
The expected data type for tag values
44 |
# File 'lib/datadog/statsd/schema/tag_definition.rb', line 44 attribute :type, Types::Strict::Symbol.default(:string) |
#valid_value?(value, transformers = {}) ⇒ Boolean
Validate a value using type checking, transformations, and custom validation
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/datadog/statsd/schema/tag_definition.rb', line 109 def valid_value?(value, transformers = {}) transformed_value = transform_value(value, transformers) # Apply type validation case type when :integer return false unless transformed_value.is_a?(Integer) || transformed_value.to_s.match?(/^\d+$/) when :string # strings are generally permissive when :symbol # symbols are generally permissive, will be converted end # Apply custom validation if present return validate.call(transformed_value) if validate.is_a?(Proc) # Apply value restrictions allows_value?(transformed_value) end |
#validate ⇒ Proc?
Custom validation procedure for tag values
52 |
# File 'lib/datadog/statsd/schema/tag_definition.rb', line 52 attribute :validate, Types::Any.optional.default(nil) |
#values ⇒ Array, ...
Allowed values for this tag (can be Array, Regexp, Proc, or single value)
40 |
# File 'lib/datadog/statsd/schema/tag_definition.rb', line 40 attribute :values, Types::Any.optional.default(nil) |