Class: Avro::Builder::Types::NamedType
- Includes:
- Aliasable, Namespaceable, ComplexType, NamedErrorHandling
- 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(value = nil) ⇒ Object
-
#name_fragment ⇒ Object
Named types that do not have an explicit name are assigned a named based on the field and its nesting.
- #namespace(value = nil) ⇒ Object
-
#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 NamedErrorHandling
Methods included from Aliasable
Methods included from Namespaceable
Methods included from ComplexType
Methods inherited from Type
#configure_options, #dsl_method?, #dsl_respond_to?, #initialize, union_with_null
Methods included from DslAttributes
Methods included from DslOptions
Instance Method Details
#cache! ⇒ Object
44 45 46 |
# File 'lib/avro/builder/types/named_type.rb', line 44 def cache! cache.add_schema_object(self) end |
#name(value = nil) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/avro/builder/types/named_type.rb', line 24 def name(value = nil) if value.nil? @name || "__#{name_fragment}_#{avro_type_name}" else type_name_instead_of_name_error! end end |
#name_fragment ⇒ Object
Named types that do not have an explicit name are assigned a named based on the field and its nesting.
50 51 52 53 |
# File 'lib/avro/builder/types/named_type.rb', line 50 def name_fragment [field && field.name_fragment, @name || (field && field.name)].compact.join('_') end |
#namespace(value = nil) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/avro/builder/types/named_type.rb', line 32 def namespace(value = nil) if value.nil? @namespace else type_namespace_instead_of_namespace_error! end 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.
58 59 60 61 62 |
# File 'lib/avro/builder/types/named_type.rb', line 58 def serialize(reference_state, overrides: {}) reference_state.definition_or_reference(fullname) do serialized_attribute_hash.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.
67 68 69 70 71 72 |
# File 'lib/avro/builder/types/named_type.rb', line 67 def to_h(_reference_state, overrides: {}) serialized_attribute_hash .merge(aliases: aliases) .merge(overrides) .reject { |_, v| v.nil? } end |
#validate! ⇒ Object
40 41 42 |
# File 'lib/avro/builder/types/named_type.rb', line 40 def validate! required_attribute_error!(:name) if field.nil? && @name.nil? end |