Class: Tros::Schema::UnionSchema
- Inherits:
-
Tros::Schema
- Object
- Tros::Schema
- Tros::Schema::UnionSchema
- Defined in:
- lib/tros/schema.rb
Constant Summary
Constants inherited from Tros::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
-
#schemas ⇒ Object
readonly
Returns the value of attribute schemas.
Attributes inherited from Tros::Schema
Instance Method Summary collapse
-
#initialize(schemas, names = nil, default_namespace = nil) ⇒ UnionSchema
constructor
A new instance of UnionSchema.
- #to_avro(names = Set.new) ⇒ Object
Methods inherited from Tros::Schema
#==, #hash, parse, real_parse, #subparse, #to_s, #type, validate, validate_strictly
Constructor Details
#initialize(schemas, names = nil, default_namespace = nil) ⇒ UnionSchema
Returns a new instance of UnionSchema.
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
# File 'lib/tros/schema.rb', line 283 def initialize(schemas, names=nil, default_namespace=nil) super(:union) schema_objects = [] schemas.each_with_index do |schema, i| new_schema = subparse(schema, names, default_namespace) ns_type = new_schema.type_sym if VALID_TYPES_SYM.include?(ns_type) && !NAMED_TYPES_SYM.include?(ns_type) && schema_objects.any?{|o| o.type_sym == ns_type } raise SchemaParseError, "#{ns_type} is already in Union" elsif ns_type == :union raise SchemaParseError, "Unions cannot contain other unions" else schema_objects << new_schema end @schemas = schema_objects end end |
Instance Attribute Details
#schemas ⇒ Object (readonly)
Returns the value of attribute schemas.
281 282 283 |
# File 'lib/tros/schema.rb', line 281 def schemas @schemas end |
Instance Method Details
#to_avro(names = Set.new) ⇒ Object
304 305 306 |
# File 'lib/tros/schema.rb', line 304 def to_avro(names=Set.new) schemas.map {|schema| schema.to_avro(names) } end |