Sha256: 2ff099b172b748e7ef91b410204708e5db3ad8172e33fb70d729d2a484c238ac

Contents?: true

Size: 860 Bytes

Versions: 1

Compression:

Stored size: 860 Bytes

Contents

# frozen_string_literal: true

module Avro
  module Builder
    module Types
      class EnumType < NamedType

        dsl_attribute :doc

        dsl_attribute :symbols do |*values|
          # Define symbols explicitly to support values as a splat or single array
          if !values.empty?
            @symbols = values.flatten
          else
            @symbols
          end
        end

        def serialize(reference_state)
          super(reference_state, overrides: serialized_attributes)
        end

        def to_h(reference_state)
          super(reference_state, overrides: serialized_attributes)
        end

        def validate!
          super
          validate_required_attribute!(:symbols)
        end

        private

        def serialized_attributes
          { symbols: symbols, doc: doc }
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
avro-builder-0.16.2 lib/avro/builder/types/enum_type.rb