Class: Avro::Schema::Field

Inherits:
Avro::Schema show all
Defined in:
lib/avro/schema.rb

Constant Summary

Constants inherited from Avro::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 collapse

Attributes inherited from Avro::Schema

#type_sym

Instance Method Summary collapse

Methods inherited from Avro::Schema

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

Constructor Details

#initialize(type, name, default = nil, order = nil, names = nil, namespace = nil) ⇒ Field

Returns a new instance of Field.



355
356
357
358
359
360
# File 'lib/avro/schema.rb', line 355

def initialize(type, name, default=nil, order=nil, names=nil, namespace=nil)
  @type = subparse(type, names, namespace)
  @name = name
  @default = default
  @order = order
end

Instance Attribute Details

#defaultObject (readonly)

Returns the value of attribute default.



353
354
355
# File 'lib/avro/schema.rb', line 353

def default
  @default
end

#nameObject (readonly)

Returns the value of attribute name.



353
354
355
# File 'lib/avro/schema.rb', line 353

def name
  @name
end

#orderObject (readonly)

Returns the value of attribute order.



353
354
355
# File 'lib/avro/schema.rb', line 353

def order
  @order
end

#typeObject (readonly)

Returns the value of attribute type.



353
354
355
# File 'lib/avro/schema.rb', line 353

def type
  @type
end

Instance Method Details

#to_avro(names = Set.new) ⇒ Object



362
363
364
365
366
367
# File 'lib/avro/schema.rb', line 362

def to_avro(names=Set.new)
  {'name' => name, 'type' => type.to_avro(names)}.tap do |avro|
    avro['default'] = default if default
    avro['order'] = order if order
  end
end