Class: Avro::Builder::Types::Type

Inherits:
Object
  • Object
show all
Includes:
DslAttributes, DslOptions, Metadata
Defined in:
lib/avro/builder/types/type.rb

Direct Known Subclasses

ComplexType, PrimitiveType

Constant Summary

Constants included from DslAttributes

DslAttributes::ATTRIBUTE_NAMES

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Metadata

attribute?, #method_missing, register, reset!, #respond_to_missing?

Methods included from DslAttributes

#dsl_attribute?, included

Methods included from DslOptions

#dsl_option?, included

Constructor Details

#initialize(avro_type_name, cache:, field: nil) ⇒ Type

Returns a new instance of Type.



17
18
19
20
21
# 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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Avro::Builder::Metadata

Instance Attribute Details

#avro_type_name ⇒ Object (readonly)

Returns the value of attribute avro_type_name.



15
16
17
# File 'lib/avro/builder/types/type.rb', line 15

def avro_type_name
  @avro_type_name
end

Class Method Details

.union_with_null(serialized) ⇒ Object

Optional fields are represented as a union of the type with :null.



46
47
48
# File 'lib/avro/builder/types/type.rb', line 46

def self.union_with_null(serialized)
  [:null, serialized]
end

Instance Method Details

#abstract? ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/avro/builder/types/type.rb', line 23

def abstract?
  !!abstract
end

#cache! ⇒ Object

Subclasses should override this method if the type definition should be cached for reuse.



57
58
# File 'lib/avro/builder/types/type.rb', line 57

def cache!
end

#configure_options(options = {}) ⇒ Object



39
40
41
42
43
# File 'lib/avro/builder/types/type.rb', line 39

def configure_options(options = {})
  options.each do |key, value|
    send("#{key}=", value)
  end
end

#dsl_method?(_name) ⇒ Boolean

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.

Returns:

  • (Boolean)


63
64
65
# File 'lib/avro/builder/types/type.rb', line 63

def dsl_method?(_name)
  false
end

#dsl_respond_to?(name) ⇒ Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/avro/builder/types/type.rb', line 67

def dsl_respond_to?(name)
  dsl_attribute?(name) || dsl_method?(name)
end

#namespace ⇒ Object



35
36
37
# File 'lib/avro/builder/types/type.rb', line 35

def namespace
  nil
end

#serialize(reference_state) ⇒ Object



27
28
29
# File 'lib/avro/builder/types/type.rb', line 27

def serialize(reference_state)
  serialized_attribute_hash(reference_state).compact
end

#to_h(reference_state) ⇒ Object



31
32
33
# File 'lib/avro/builder/types/type.rb', line 31

def to_h(reference_state)
  serialized_attribute_hash(reference_state).compact
end

#validate! ⇒ Object

Subclasses should override this method to check for the presence of required DSL attributes.



52
53
# File 'lib/avro/builder/types/type.rb', line 52

def validate!
end