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

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

Overview

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.

Direct Known Subclasses

ArrayType, MapType, NamedType, UnionType

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DslAttributes

#dsl_attribute?, included

Methods included from DslOptions

#dsl_option?, included

Constructor Details

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

Returns a new instance of Type.



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

def initialize(type_name, cache:, field: nil)
  @type_name = type_name
  @cache = cache
  @field = field
end

Instance Attribute Details

#type_nameObject (readonly)

Returns the value of attribute type_name.



11
12
13
# File 'lib/avro/builder/types/type.rb', line 11

def type_name
  @type_name
end

Class Method Details

.union_with_null(serialized) ⇒ Object

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



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

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

Instance Method Details

#cache!Object

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



43
44
# File 'lib/avro/builder/types/type.rb', line 43

def cache!
end

#configure_options(_options = {}) ⇒ Object



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

def configure_options(_options = {})
  # No-op
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)


49
50
51
# File 'lib/avro/builder/types/type.rb', line 49

def dsl_method?(_name)
  false
end

#dsl_respond_to?(name) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#namespaceObject



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

def namespace
  nil
end

#serialize(_reference_state) ⇒ Object



19
20
21
# File 'lib/avro/builder/types/type.rb', line 19

def serialize(_reference_state)
  type_name
end

#validate!Object

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



38
39
# File 'lib/avro/builder/types/type.rb', line 38

def validate!
end