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
#==, #be_read?, #hash, #md5_fingerprint, #mutual_read?, parse, #read?, 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.
259 260 261 262 263 264 265 266 267 268 269 270 271 |
# File 'lib/avro/schema.rb', line 259 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 = if fields RecordSchema.make_field_objects(fields, names, self.namespace) else {} end end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
235 236 237 |
# File 'lib/avro/schema.rb', line 235 def fields @fields end |
Class Method Details
.make_field_objects(field_data, names, namespace = nil) ⇒ Object
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/avro/schema.rb', line 237 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.key?('default') ? field['default'] : :no_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
273 274 275 |
# File 'lib/avro/schema.rb', line 273 def fields_hash @fields_hash ||= fields.inject({}){|hsh, field| hsh[field.name] = field; hsh } end |
#to_avro(names = Set.new) ⇒ Object
277 278 279 280 281 282 283 284 285 286 |
# File 'lib/avro/schema.rb', line 277 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 |