class Avro::Schema::RecordSchema

Attributes

fields[R]

Public Class Methods

make_field_objects(field_data, names, namespace=nil) click to toggle source
    # File lib/avro/schema.rb
202 def self.make_field_objects(field_data, names, namespace=nil)
203   field_objects, field_names = [], Set.new
204   field_data.each_with_index do |field, i|
205     if field.respond_to?(:[]) # TODO(jmhodges) wtffffff
206       type = field['type']
207       name = field['name']
208       default = field.key?('default') ? field['default'] : :no_default
209       order = field['order']
210       new_field = Field.new(type, name, default, order, names, namespace)
211       # make sure field name has not been used yet
212       if field_names.include?(new_field.name)
213         raise SchemaParseError, "Field name #{new_field.name.inspect} is already in use"
214       end
215       field_names << new_field.name
216     else
217       raise SchemaParseError, "Not a valid field: #{field}"
218     end
219     field_objects << new_field
220   end
221   field_objects
222 end
new(name, namespace, fields, names=nil, schema_type=:record) click to toggle source
Calls superclass method Avro::Schema::NamedSchema::new
    # File lib/avro/schema.rb
224 def initialize(name, namespace, fields, names=nil, schema_type=:record)
225   if schema_type == :request || schema_type == 'request'
226     @type_sym = schema_type.to_sym
227     @namespace = namespace
228   else
229     super(schema_type, name, namespace, names)
230   end
231   @fields = if fields
232               RecordSchema.make_field_objects(fields, names, self.namespace)
233             else
234               {}
235             end
236 end

Public Instance Methods

fields_hash() click to toggle source
    # File lib/avro/schema.rb
238 def fields_hash
239   @fields_hash ||= fields.inject({}){|hsh, field| hsh[field.name] = field; hsh }
240 end
to_avro(names=Set.new) click to toggle source
Calls superclass method Avro::Schema::NamedSchema#to_avro
    # File lib/avro/schema.rb
242 def to_avro(names=Set.new)
243   hsh = super
244   return hsh unless hsh.is_a?(Hash)
245   hsh['fields'] = @fields.map {|f| f.to_avro(names) }
246   if type_sym == :request
247     hsh['fields']
248   else
249     hsh
250   end
251 end