Class: Datadog::Statsd::Schema::SchemaBuilder
- Inherits:
-
Object
- Object
- Datadog::Statsd::Schema::SchemaBuilder
- Defined in:
- lib/datadog/statsd/schema/schema_builder.rb
Overview
Builder class for constructing metric schemas using a DSL Provides a fluent interface for defining namespaces, tags, and metrics
Defined Under Namespace
Classes: MetricBuilder, MetricsBuilder, NamespaceBuilder, TagsBuilder, TransformerBuilder
Instance Attribute Summary collapse
-
#root_namespace ⇒ Namespace
readonly
The root namespace of the schema being built.
-
#transformers {|TransformerBuilder| ... } ⇒ Hash<Symbol, Proc>
readonly
Define transformers that can be used by tag definitions.
Instance Method Summary collapse
-
#build ⇒ Namespace
Build the final schema (returns the root namespace).
-
#initialize ⇒ SchemaBuilder
constructor
Initialize a new schema builder.
-
#namespace(name) {|NamespaceBuilder| ... } ⇒ void
Define a namespace.
-
#validate! ⇒ void
Validate the schema for consistency.
Constructor Details
#initialize ⇒ SchemaBuilder
Initialize a new schema builder
38 39 40 41 |
# File 'lib/datadog/statsd/schema/schema_builder.rb', line 38 def initialize @transformers = {} @root_namespace = Namespace.new(name: :root) end |
Instance Attribute Details
#root_namespace ⇒ Namespace (readonly)
The root namespace of the schema being built
35 36 37 |
# File 'lib/datadog/statsd/schema/schema_builder.rb', line 35 def root_namespace @root_namespace end |
#transformers {|TransformerBuilder| ... } ⇒ Hash<Symbol, Proc> (readonly)
Define transformers that can be used by tag definitions
31 32 33 |
# File 'lib/datadog/statsd/schema/schema_builder.rb', line 31 def transformers @transformers end |
Instance Method Details
#build ⇒ Namespace
Build the final schema (returns the root namespace)
76 77 78 |
# File 'lib/datadog/statsd/schema/schema_builder.rb', line 76 def build @root_namespace end |
#namespace(name) {|NamespaceBuilder| ... } ⇒ void
This method returns an undefined value.
Define a namespace
66 67 68 69 70 71 72 |
# File 'lib/datadog/statsd/schema/schema_builder.rb', line 66 def namespace(name, &) builder = NamespaceBuilder.new(name, @transformers) builder.instance_eval(&) if block_given? namespace_def = builder.build @root_namespace = @root_namespace.add_namespace(namespace_def) end |
#validate! ⇒ void
This method returns an undefined value.
Validate the schema for consistency
83 84 85 86 |
# File 'lib/datadog/statsd/schema/schema_builder.rb', line 83 def validate! errors = @root_namespace.validate_tag_references raise SchemaError, "Schema validation failed: #{errors.join(", ")}" unless errors.empty? end |