Class: Avro::Builder::Types::Type
- Inherits:
-
Object
- Object
- Avro::Builder::Types::Type
- 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.
Instance Attribute Summary collapse
-
#avro_type_name ⇒ Object
readonly
Returns the value of attribute avro_type_name.
Class Method Summary collapse
-
.union_with_null(serialized) ⇒ Object
Optional fields are represented as a union of the type with :null.
Instance Method Summary collapse
- #abstract? ⇒ Boolean
-
#cache! ⇒ Object
Subclasses should override this method if the type definition should be cached for reuse.
- #configure_options(options = {}) ⇒ Object
-
#dsl_method?(_name) ⇒ Boolean
Subclasses can override this method to indicate that the name is a method that the type exposes in the DSL.
- #dsl_respond_to?(name) ⇒ Boolean
-
#initialize(avro_type_name, cache:, field: nil) ⇒ Type
constructor
A new instance of Type.
- #namespace ⇒ Object
- #serialize(_reference_state) ⇒ Object
- #to_h(_reference_state) ⇒ Object
-
#validate! ⇒ Object
Subclasses should override this method to check for the presence of required DSL attributes.
Methods included from DslAttributes
Methods included from DslOptions
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 |
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.
51 52 53 |
# File 'lib/avro/builder/types/type.rb', line 51 def self.union_with_null(serialized) [:null, serialized] end |
Instance Method Details
#abstract? ⇒ 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.
62 63 |
# File 'lib/avro/builder/types/type.rb', line 62 def cache! end |
#configure_options(options = {}) ⇒ Object
44 45 46 47 48 |
# File 'lib/avro/builder/types/type.rb', line 44 def ( = {}) .each do |key, value| send("#{key}=", value) if dsl_option?(key) 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.
68 69 70 |
# File 'lib/avro/builder/types/type.rb', line 68 def dsl_method?(_name) false end |
#dsl_respond_to?(name) ⇒ Boolean
72 73 74 |
# File 'lib/avro/builder/types/type.rb', line 72 def dsl_respond_to?(name) dsl_attribute?(name) || dsl_method?(name) end |
#namespace ⇒ Object
40 41 42 |
# File 'lib/avro/builder/types/type.rb', line 40 def namespace nil end |
#serialize(_reference_state) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/avro/builder/types/type.rb', line 27 def serialize(_reference_state) if logical_type { type: avro_type_name, logicalType: logical_type } else avro_type_name end end |
#to_h(_reference_state) ⇒ Object
35 36 37 38 |
# File 'lib/avro/builder/types/type.rb', line 35 def to_h(_reference_state) { type: avro_type_name, logicalType: logical_type } .reject { |_, v| v.nil? } end |
#validate! ⇒ Object
Subclasses should override this method to check for the presence of required DSL attributes.
57 58 |
# File 'lib/avro/builder/types/type.rb', line 57 def validate! end |