Class: Tros::Schema::PrimitiveSchema

Inherits:
Tros::Schema show all
Defined in:
lib/tros/schema.rb

Overview

Valid primitive types are in PRIMITIVE_TYPES.

Constant Summary

Constants inherited from Tros::Schema

INT_MAX_VALUE, INT_MIN_VALUE, LONG_MAX_VALUE, LONG_MIN_VALUE, NAMED_TYPES, NAMED_TYPES_SYM, PRIMITIVE_TYPES, PRIMITIVE_TYPES_SYM, VALID_TYPES, VALID_TYPES_SYM

Instance Attribute Summary

Attributes inherited from Tros::Schema

#type_sym

Instance Method Summary collapse

Methods inherited from Tros::Schema

#==, #hash, parse, real_parse, #subparse, #to_s, #type, validate, validate_strictly

Constructor Details

#initialize(type) ⇒ PrimitiveSchema

Returns a new instance of PrimitiveSchema.



330
331
332
333
334
335
336
337
338
# File 'lib/tros/schema.rb', line 330

def initialize(type)
  if PRIMITIVE_TYPES_SYM.include?(type)
    super(type)
  elsif PRIMITIVE_TYPES.include?(type)
    super(type.to_sym)
  else
    raise AvroError.new("#{type} is not a valid primitive type.")
  end
end

Instance Method Details

#to_avro(names = nil) ⇒ Object



340
341
342
343
# File 'lib/tros/schema.rb', line 340

def to_avro(names=nil)
  hsh = super
  hsh.size == 1 ? type : hsh
end