Class: Avro::Builder::Types::NamedType
- Includes:
- Aliasable, Namespaceable, ComplexType, ConfigurableType
- Defined in:
- lib/avro/builder/types/named_type.rb
Overview
This is an abstract class that represents a type that can be defined with a name, outside a record.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Type
Instance Method Summary collapse
- #cache! ⇒ Object
-
#name_fragment ⇒ Object
Named types that do not have an explicit name are assigned a named based on the field and its nesting.
-
#serialize(reference_state, overrides: {}) ⇒ Object
As a type for a field Subclasses may call super with additional overrides to be added to the serialized value.
-
#to_h(_reference_state, overrides: {}) ⇒ Object
As a top-level, named type Subclasses may call super with additional overrides to be added to the hash representation.
- #validate! ⇒ Object
Methods included from Aliasable
Methods included from ConfigurableType
Methods included from Namespaceable
Methods included from ComplexType
included, #initialize, #namespace
Methods inherited from Type
#configure_options, #dsl_method?, #dsl_respond_to?, #initialize, #namespace, union_with_null
Methods included from DslAttributes
Methods included from DslOptions
Instance Method Details
#cache! ⇒ Object
28 29 30 |
# File 'lib/avro/builder/types/named_type.rb', line 28 def cache! cache.add_schema_object(self) end |
#name_fragment ⇒ Object
Named types that do not have an explicit name are assigned a named based on the field and its nesting.
34 35 36 37 |
# File 'lib/avro/builder/types/named_type.rb', line 34 def name_fragment [field && field.name_fragment, @name || (field && field.name)].compact.join('_') end |
#serialize(reference_state, overrides: {}) ⇒ Object
As a type for a field Subclasses may call super with additional overrides to be added to the serialized value.
42 43 44 45 46 47 48 49 50 |
# File 'lib/avro/builder/types/named_type.rb', line 42 def serialize(reference_state, overrides: {}) reference_state.definition_or_reference(fullname) do { name: name, type: type_name, namespace: namespace }.merge(overrides).reject { |_, v| v.nil? } end end |
#to_h(_reference_state, overrides: {}) ⇒ Object
As a top-level, named type Subclasses may call super with additional overrides to be added to the hash representation.
55 56 57 58 59 60 61 62 |
# File 'lib/avro/builder/types/named_type.rb', line 55 def to_h(_reference_state, overrides: {}) { name: name, type: type_name, namespace: namespace, aliases: aliases }.merge(overrides).reject { |_, v| v.nil? } end |
#validate! ⇒ Object
24 25 26 |
# File 'lib/avro/builder/types/named_type.rb', line 24 def validate! required_attribute_error!(:name) if field.nil? && @name.nil? end |