Class: Avro::Schema::EnumSchema
- Inherits:
-
NamedSchema
- Object
- Avro::Schema
- NamedSchema
- Avro::Schema::EnumSchema
- Defined in:
- lib/avro/schema.rb
Constant Summary collapse
- SYMBOL_REGEX =
/^[A-Za-z_][A-Za-z0-9_]*$/.freeze
Constants inherited from Avro::Schema
CRC_EMPTY, DECIMAL_LOGICAL_TYPE, DEFAULT_VALIDATE_OPTIONS, INT_MAX_VALUE, INT_MIN_VALUE, LONG_MAX_VALUE, LONG_MIN_VALUE, NAMED_TYPES, NAMED_TYPES_SYM, NAME_REGEX, PRIMITIVE_TYPES, PRIMITIVE_TYPES_SYM, SINGLE_OBJECT_MAGIC_NUMBER, VALID_TYPES, VALID_TYPES_SYM
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
-
#symbols ⇒ Object
readonly
Returns the value of attribute symbols.
Attributes inherited from NamedSchema
Attributes inherited from Avro::Schema
Instance Method Summary collapse
-
#initialize(name, space, symbols, names = nil, doc = nil, default = nil, aliases = nil) ⇒ EnumSchema
constructor
A new instance of EnumSchema.
- #to_avro(_names = Set.new) ⇒ Object
Methods inherited from NamedSchema
#fullname, #fullname_aliases, #match_fullname?, #match_schema?
Methods inherited from Avro::Schema
#==, #be_read?, #crc_64_avro_fingerprint, #hash, #initFPTable, #md5_fingerprint, #mutual_read?, parse, #read?, real_parse, #sha256_fingerprint, #single_object_encoding_header, #single_object_schema_fingerprint, #subparse, #to_s, #type, #type_adapter, validate
Constructor Details
#initialize(name, space, symbols, names = nil, doc = nil, default = nil, aliases = nil) ⇒ EnumSchema
Returns a new instance of EnumSchema.
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 |
# File 'lib/avro/schema.rb', line 430 def initialize(name, space, symbols, names=nil, doc=nil, default=nil, aliases=nil) if symbols.uniq.length < symbols.length fail_msg = "Duplicate symbol: #{symbols}" raise Avro::SchemaParseError, fail_msg end if !Avro.disable_enum_symbol_validation invalid_symbols = symbols.select { |symbol| symbol !~ SYMBOL_REGEX } if invalid_symbols.any? raise SchemaParseError, "Invalid symbols for #{name}: #{invalid_symbols.join(', ')} don't match #{SYMBOL_REGEX.inspect}" end end if default && !symbols.include?(default) raise Avro::SchemaParseError, "Default '#{default}' is not a valid symbol for enum #{name}" end super(:enum, name, space, names, doc, nil, aliases) @default = default @symbols = symbols end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
428 429 430 |
# File 'lib/avro/schema.rb', line 428 def default @default end |
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
428 429 430 |
# File 'lib/avro/schema.rb', line 428 def doc @doc end |
#symbols ⇒ Object (readonly)
Returns the value of attribute symbols.
428 429 430 |
# File 'lib/avro/schema.rb', line 428 def symbols @symbols end |
Instance Method Details
#to_avro(_names = Set.new) ⇒ Object
454 455 456 457 458 459 460 461 |
# File 'lib/avro/schema.rb', line 454 def to_avro(_names=Set.new) avro = super if avro.is_a?(Hash) avro['symbols'] = symbols avro['default'] = default if default end avro end |