Class: Avro::Schema::NamedSchema

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

Direct Known Subclasses

EnumSchema, FixedSchema, RecordSchema

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, #type_adapter, validate

Constructor Details

#initialize(type, name, namespace = nil, names = nil, doc = nil, logical_type = nil, aliases = nil) ⇒ NamedSchema

Returns a new instance of NamedSchema.



255
256
257
258
259
260
261
262
# File 'lib/avro/schema.rb', line 255

def initialize(type, name, namespace=nil, names=nil, doc=nil, logical_type=nil, aliases=nil)
  super(type, logical_type)
  @name, @namespace = Name.extract_namespace(name, namespace)
  @doc = doc
  @aliases = aliases
  validate_aliases! if aliases
  Name.add_name(names, self)
end

Instance Attribute Details

#aliasesObject (readonly)

Returns the value of attribute aliases.



253
254
255
# File 'lib/avro/schema.rb', line 253

def aliases
  @aliases
end

#nameObject (readonly)

Returns the value of attribute name.



253
254
255
# File 'lib/avro/schema.rb', line 253

def name
  @name
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



253
254
255
# File 'lib/avro/schema.rb', line 253

def namespace
  @namespace
end

Instance Method Details

#fullnameObject



277
278
279
# File 'lib/avro/schema.rb', line 277

def fullname
  @fullname ||= Name.make_fullname(@name, @namespace)
end

#fullname_aliasesObject



281
282
283
284
285
286
287
# File 'lib/avro/schema.rb', line 281

def fullname_aliases
  @fullname_aliases ||= if aliases
                          aliases.map { |a| Name.make_fullname(a, namespace) }
                        else
                          []
                        end
end

#match_fullname?(name) ⇒ Boolean

Returns:

  • (Boolean)


289
290
291
# File 'lib/avro/schema.rb', line 289

def match_fullname?(name)
  name == fullname || fullname_aliases.include?(name)
end

#match_schema?(schema) ⇒ Boolean

Returns:

  • (Boolean)


293
294
295
# File 'lib/avro/schema.rb', line 293

def match_schema?(schema)
  type_sym == schema.type_sym && match_fullname?(schema.fullname)
end

#to_avro(names = Set.new) ⇒ Object



264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/avro/schema.rb', line 264

def to_avro(names=Set.new)
  if @name
    return fullname if names.include?(fullname)
    names << fullname
  end
  props = {'name' => @name}
  props.merge!('namespace' => @namespace) if @namespace
  props['namespace'] = @namespace if @namespace
  props['doc'] = @doc if @doc
  props['aliases'] = aliases if aliases && aliases.any?
  super.merge props
end