Class: Avro::Schema::RecordSchema
- Inherits:
-
NamedSchema
- Object
- Avro::Schema
- NamedSchema
- Avro::Schema::RecordSchema
- 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
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
Attributes inherited from NamedSchema
Attributes inherited from Avro::Schema
Class Method Summary collapse
Instance Method Summary collapse
- #fields_hash ⇒ Object
-
#initialize(name, namespace, fields, names = nil, schema_type = :record) ⇒ RecordSchema
constructor
A new instance of RecordSchema.
- #to_avro(names = Set.new) ⇒ Object
Methods inherited from NamedSchema
Methods inherited from Avro::Schema
#==, #hash, #md5_fingerprint, parse, real_parse, #sha256_fingerprint, #subparse, #to_s, #type, #type_adapter, validate
Constructor Details
#initialize(name, namespace, fields, names = nil, schema_type = :record) ⇒ RecordSchema
Returns a new instance of RecordSchema.
247 248 249 250 251 252 253 254 255 |
# File 'lib/avro/schema.rb', line 247 def initialize(name, namespace, fields, names=nil, schema_type=:record) if schema_type == :request || schema_type == 'request' @type_sym = schema_type.to_sym @namespace = namespace else super(schema_type, name, namespace, names) end @fields = RecordSchema.make_field_objects(fields, names, self.namespace) end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
223 224 225 |
# File 'lib/avro/schema.rb', line 223 def fields @fields end |
Class Method Details
.make_field_objects(field_data, names, namespace = nil) ⇒ Object
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/avro/schema.rb', line 225 def self.make_field_objects(field_data, names, namespace=nil) field_objects, field_names = [], Set.new field_data.each_with_index do |field, i| if field.respond_to?(:[]) # TODO(jmhodges) wtffffff type = field['type'] name = field['name'] default = field['default'] order = field['order'] new_field = Field.new(type, name, default, order, names, namespace) # make sure field name has not been used yet if field_names.include?(new_field.name) raise SchemaParseError, "Field name #{new_field.name.inspect} is already in use" end field_names << new_field.name else raise SchemaParseError, "Not a valid field: #{field}" end field_objects << new_field end field_objects end |
Instance Method Details
#fields_hash ⇒ Object
257 258 259 |
# File 'lib/avro/schema.rb', line 257 def fields_hash @fields_hash ||= fields.inject({}){|hsh, field| hsh[field.name] = field; hsh } end |
#to_avro(names = Set.new) ⇒ Object
261 262 263 264 265 266 267 268 269 270 |
# File 'lib/avro/schema.rb', line 261 def to_avro(names=Set.new) hsh = super return hsh unless hsh.is_a?(Hash) hsh['fields'] = @fields.map {|f| f.to_avro(names) } if type_sym == :request hsh['fields'] else hsh end end |