class Avro::Builder::Types::NamedType

This is an abstract class that represents a type that can be defined with a name, outside a record.

Public Instance Methods

cache!() click to toggle source
# File lib/avro/builder/types/named_type.rb, line 46
def cache!
  cache.add_schema_object(self)
end
name(value = nil) click to toggle source
# File lib/avro/builder/types/named_type.rb, line 26
def name(value = nil)
  if value.nil?
    @name || "__#{name_fragment}_#{avro_type_name}"
  else
    type_name_instead_of_name_error!
  end
end
name_fragment() click to toggle source

Named types that do not have an explicit name are assigned a named based on the field and its nesting.

# File lib/avro/builder/types/named_type.rb, line 52
def name_fragment
  [field && field.name_fragment,
   @name || (field && field.name)].compact.join('_')
end
namespace(value = nil) click to toggle source
# File lib/avro/builder/types/named_type.rb, line 34
def namespace(value = nil)
  if value.nil?
    @namespace
  else
    type_namespace_instead_of_namespace_error!
  end
end
serialize(reference_state, overrides: {}) click to toggle source

As a type for a field Subclasses may call super with additional overrides to be added to the serialized value.

# File lib/avro/builder/types/named_type.rb, line 60
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: {}) click to toggle source

As a top-level, named type Subclasses may call super with additional overrides to be added to the hash representation.

# File lib/avro/builder/types/named_type.rb, line 69
def to_h(_reference_state, overrides: {})
  serialized_attribute_hash
    .merge(aliases: aliases)
    .merge(overrides)
    .reject { |_, v| v.nil? }
end
validate!() click to toggle source
# File lib/avro/builder/types/named_type.rb, line 42
def validate!
  required_attribute_error!(:name) if field.nil? && @name.nil?
end

Private Instance Methods

serialized_attribute_hash() click to toggle source
# File lib/avro/builder/types/named_type.rb, line 78
def serialized_attribute_hash
  {
    name: name,
    type: avro_type_name,
    namespace: namespace,
    logicalType: logical_type
  }
end