Sha256: 5b9746a9d9d6f2bbe366fa2b79582f19d5eabd03bf6e8b004e845d648d153f60

Contents?: true

Size: 921 Bytes

Versions: 3

Compression:

Stored size: 921 Bytes

Contents

# frozen_string_literal: true

require_relative 'base'
require 'json'

module Deimos
  module SchemaClass
    # Base Class for Enum Classes generated from Avro.
    class Enum < Base

      attr_accessor :value

      # @param other [Deimos::SchemaClass::Enum]
      def ==(other)
        other.is_a?(self.class) ? other.value == @value : other == @value
      end

      # @return [String]
      def to_s
        @value.to_s
      end

      # @param value [String]
      def initialize(value)
        @value = value
      end

      # Returns all the valid symbols for this enum.
      # @return [Array<String>]
      def symbols
        raise NotImplementedError
      end

      # :nodoc:
      def as_json(_opts={})
        @value
      end

      # :nodoc:
      def self.initialize_from_value(value)
        return nil if value.nil?

        value.is_a?(self) ? value : self.new(value)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
deimos-ruby-1.16.3 lib/deimos/schema_class/enum.rb
deimos-ruby-1.16.2 lib/deimos/schema_class/enum.rb
deimos-ruby-1.16.1 lib/deimos/schema_class/enum.rb