Class: Avro::LogicalTypes::LogicalTypeWithSchema

Inherits:
Object
  • Object
show all
Defined in:
lib/avro/logical_types.rb

Overview

Base class for logical types requiring a schema to be present

Direct Known Subclasses

BytesDecimal

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema) ⇒ LogicalTypeWithSchema

Build a new instance of a logical type using the provided schema

Parameters:

  • schema (Avro::Schema)

    The schema to use with this instance

Raises:

  • (ArgumentError)

    If the provided schema is nil



40
41
42
43
44
# File 'lib/avro/logical_types.rb', line 40

def initialize(schema)
  raise ArgumentError, 'schema is required' if schema.nil?

  @schema = schema
end

Instance Attribute Details

#schemaAvro::Schema (readonly)

Returns The schema this logical type is dealing with.

Returns:

  • (Avro::Schema)

    The schema this logical type is dealing with



30
31
32
# File 'lib/avro/logical_types.rb', line 30

def schema
  @schema
end

Instance Method Details

#decode(datum) ⇒ Object

Decode the provided datum

Parameters:

  • datum (Object)

    The datum to decode

Raises:

  • (NotImplementedError)

    Subclass will need to override this method



64
65
66
# File 'lib/avro/logical_types.rb', line 64

def decode(datum)
  raise NotImplementedError
end

#encode(datum) ⇒ Object

Encode the provided datum

Parameters:

  • datum (Object)

    The datum to encode

Raises:

  • (NotImplementedError)

    Subclass will need to override this method



53
54
55
# File 'lib/avro/logical_types.rb', line 53

def encode(datum)
  raise NotImplementedError
end