Class: Avro::Schema::Field

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

Constant Summary

Constants inherited from Avro::Schema

CRC_EMPTY, DECIMAL_LOGICAL_TYPE, DEFAULT_VALIDATE_OPTIONS, INT_MAX_VALUE, INT_MIN_VALUE, LONG_MAX_VALUE, LONG_MIN_VALUE, NAMED_TYPES, NAMED_TYPES_SYM, NAME_REGEX, PRIMITIVE_TYPES, PRIMITIVE_TYPES_SYM, SINGLE_OBJECT_MAGIC_NUMBER, 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?, #crc_64_avro_fingerprint, #hash, #initFPTable, #md5_fingerprint, #mutual_read?, parse, #read?, real_parse, #sha256_fingerprint, #single_object_encoding_header, #single_object_schema_fingerprint, #subparse, #to_s, #type_adapter, validate

Constructor Details

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

rubocop:disable Lint/MissingSuper



568
569
570
571
572
573
574
575
576
577
578
# File 'lib/avro/schema.rb', line 568

def initialize(type, name, default=:no_default, order=nil, names=nil, namespace=nil, doc=nil, aliases=nil) # rubocop:disable Lint/MissingSuper
  @type = subparse(type, names, namespace)
  @name = name
  @default = default
  @order = order
  @doc = doc
  @aliases = aliases
  @type_adapter = nil
  validate_aliases! if aliases
  validate_default! if default? && !Avro.disable_field_default_validation
end

Instance Attribute Details

#aliasesObject (readonly)

Returns the value of attribute aliases.



566
567
568
# File 'lib/avro/schema.rb', line 566

def aliases
  @aliases
end

#defaultObject (readonly)

Returns the value of attribute default.



566
567
568
# File 'lib/avro/schema.rb', line 566

def default
  @default
end

#docObject (readonly)

Returns the value of attribute doc.



566
567
568
# File 'lib/avro/schema.rb', line 566

def doc
  @doc
end

#nameObject (readonly)

Returns the value of attribute name.



566
567
568
# File 'lib/avro/schema.rb', line 566

def name
  @name
end

#orderObject (readonly)

Returns the value of attribute order.



566
567
568
# File 'lib/avro/schema.rb', line 566

def order
  @order
end

#typeObject (readonly)

Returns the value of attribute type.



566
567
568
# File 'lib/avro/schema.rb', line 566

def type
  @type
end

Instance Method Details

#alias_namesObject



592
593
594
# File 'lib/avro/schema.rb', line 592

def alias_names
  @alias_names ||= Array(aliases)
end

#default?Boolean

Returns:

  • (Boolean)


580
581
582
# File 'lib/avro/schema.rb', line 580

def default?
  @default != :no_default
end

#to_avro(names = Set.new) ⇒ Object



584
585
586
587
588
589
590
# File 'lib/avro/schema.rb', line 584

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