Sha256: e428223f960f8457b9b178d5a32f2ccd30569814857e9d8be249dca5197141cc

Contents?: true

Size: 708 Bytes

Versions: 249

Compression:

Stored size: 708 Bytes

Contents

# frozen_string_literal: true
# typed: true

module T::Types
  # validates that the provided value is within a given set/enum
  class Enum < Base
    extend T::Sig

    attr_reader :values

    def initialize(values)
      @values = values
    end

    # overrides Base
    def valid?(obj)
      @values.member?(obj)
    end

    # overrides Base
    private def subtype_of_single?(other)
      case other
      when Enum
        (other.values - @values).empty?
      else
        false
      end
    end

    # overrides Base
    def name
      @name ||= "T.deprecated_enum([#{@values.map(&:inspect).join(', ')}])"
    end

    # overrides Base
    def describe_obj(obj)
      obj.inspect
    end
  end
end

Version data entries

249 entries across 243 versions & 3 rubygems

Version Path
sorbet-runtime-0.5.10987 lib/types/types/enum.rb
sorbet-runtime-0.5.10985 lib/types/types/enum.rb
sorbet-runtime-0.5.10984 lib/types/types/enum.rb
sorbet-runtime-0.5.10983 lib/types/types/enum.rb
sorbet-runtime-0.5.10981 lib/types/types/enum.rb
sorbet-runtime-0.5.10978 lib/types/types/enum.rb
sorbet-runtime-0.5.10974 lib/types/types/enum.rb
sorbet-runtime-0.5.10972 lib/types/types/enum.rb
sorbet-runtime-0.5.10969 lib/types/types/enum.rb
sorbet-runtime-0.5.10965 lib/types/types/enum.rb
sorbet-runtime-0.5.10962 lib/types/types/enum.rb
sorbet-runtime-0.5.10958 lib/types/types/enum.rb
sorbet-runtime-0.5.10957 lib/types/types/enum.rb
sorbet-runtime-0.5.10953 lib/types/types/enum.rb
sorbet-runtime-0.5.10952 lib/types/types/enum.rb
sorbet-runtime-0.5.10950 lib/types/types/enum.rb
sorbet-runtime-0.5.10948 lib/types/types/enum.rb
sorbet-runtime-0.5.10946 lib/types/types/enum.rb
sorbet-runtime-0.5.10941 lib/types/types/enum.rb
sorbet-runtime-0.5.10940 lib/types/types/enum.rb