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