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

#logical_type, #type_sym

Instance Method Summary collapse

Methods inherited from Avro::Schema

#==, #be_read?, #hash, #md5_fingerprint, #mutual_read?, parse, #read?, real_parse, #sha256_fingerprint, #subparse, #to_s, #type_adapter, validate

Constructor Details

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

Returns a new instance of Field.



371
372
373
374
375
376
377
378
# File 'lib/avro/schema.rb', line 371

def initialize(type, name, default=:no_default, order=nil, names=nil, namespace=nil, doc=nil)
  @type = subparse(type, names, namespace)
  @name = name
  @default = default
  @order = order
  @doc = doc
  validate_default! if default? && !Avro.disable_field_default_validation
end

Instance Attribute Details

#defaultObject (readonly)

Returns the value of attribute default.



369
370
371
# File 'lib/avro/schema.rb', line 369

def default
  @default
end

#docObject (readonly)

Returns the value of attribute doc.



369
370
371
# File 'lib/avro/schema.rb', line 369

def doc
  @doc
end

#nameObject (readonly)

Returns the value of attribute name.



369
370
371
# File 'lib/avro/schema.rb', line 369

def name
  @name
end

#orderObject (readonly)

Returns the value of attribute order.



369
370
371
# File 'lib/avro/schema.rb', line 369

def order
  @order
end

#typeObject (readonly)

Returns the value of attribute type.



369
370
371
# File 'lib/avro/schema.rb', line 369

def type
  @type
end

Instance Method Details

#default?Boolean

Returns:

  • (Boolean)


380
381
382
# File 'lib/avro/schema.rb', line 380

def default?
  @default != :no_default
end

#to_avro(names = Set.new) ⇒ Object



384
385
386
387
388
389
390
# File 'lib/avro/schema.rb', line 384

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
    avro['doc'] = doc if doc
  end
end