class Avro::Builder::Types::Type
Base class for simple types. The type name is specified when the type is constructed. The type has no additional attributes, and the type is serialized as just the type name.
Attributes
avro_type_name[R]
cache[RW]
field[RW]
Public Class Methods
new(avro_type_name, cache:, field: nil)
click to toggle source
# File lib/avro/builder/types/type.rb, line 17 def initialize(avro_type_name, cache:, field: nil) @avro_type_name = avro_type_name @cache = cache @field = field end
union_with_null(serialized)
click to toggle source
Optional fields are represented as a union of the type with :null.
# File lib/avro/builder/types/type.rb, line 50 def self.union_with_null(serialized) [:null, serialized] end
Public Instance Methods
abstract?()
click to toggle source
# File lib/avro/builder/types/type.rb, line 23 def abstract? !!abstract end
cache!()
click to toggle source
Subclasses should override this method if the type definition should be cached for reuse.
# File lib/avro/builder/types/type.rb, line 61 def cache! end
configure_options(options = {})
click to toggle source
# File lib/avro/builder/types/type.rb, line 43 def configure_options(options = {}) options.each do |key, value| send("#{key}=", value) if dsl_option?(key) end end
dsl_method?(_name)
click to toggle source
Subclasses can override this method to indicate that the name is a method that the type exposes in the DSL
. These methods are in addition to the methods for setting attributes on a type.
# File lib/avro/builder/types/type.rb, line 67 def dsl_method?(_name) false end
dsl_respond_to?(name)
click to toggle source
# File lib/avro/builder/types/type.rb, line 71 def dsl_respond_to?(name) dsl_attribute?(name) || dsl_method?(name) end
namespace()
click to toggle source
# File lib/avro/builder/types/type.rb, line 39 def namespace nil end
serialize(_reference_state, overrides: {})
click to toggle source
# File lib/avro/builder/types/type.rb, line 27 def serialize(_reference_state, overrides: {}) if logical_type serialized_attributes_hash(overrides) else avro_type_name end end
to_h(_reference_state, overrides: {})
click to toggle source
# File lib/avro/builder/types/type.rb, line 35 def to_h(_reference_state, overrides: {}) serialized_attributes_hash(overrides) end
validate!()
click to toggle source
Subclasses should override this method to check for the presence of required DSL
attributes.
# File lib/avro/builder/types/type.rb, line 56 def validate! end
Private Instance Methods
required_attribute_error!(attribute_name)
click to toggle source
# File lib/avro/builder/types/type.rb, line 83 def required_attribute_error!(attribute_name) raise RequiredAttributeError.new(type: avro_type_name, attribute: attribute_name, field: field && field.name, name: @name) end
serialized_attributes_hash(overrides)
click to toggle source
# File lib/avro/builder/types/type.rb, line 77 def serialized_attributes_hash(overrides) { type: avro_type_name, logicalType: logical_type } .merge(overrides) .reject { |_, v| v.nil? } end
validate_required_attribute!(attribute_name)
click to toggle source
# File lib/avro/builder/types/type.rb, line 90 def validate_required_attribute!(attribute_name) value = public_send(attribute_name) required_attribute_error!(attribute_name) if value.nil? || value.respond_to?(:empty?) && value.empty? end