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.11170 lib/types/types/enum.rb
sorbet-runtime-0.5.11164 lib/types/types/enum.rb
sorbet-runtime-0.5.11163 lib/types/types/enum.rb
sorbet-runtime-0.5.11162 lib/types/types/enum.rb
sorbet-runtime-0.5.11158 lib/types/types/enum.rb
sorbet-runtime-0.5.11156 lib/types/types/enum.rb
sorbet-runtime-0.5.11155 lib/types/types/enum.rb
sorbet-runtime-0.5.11152 lib/types/types/enum.rb
sorbet-runtime-0.5.11151 lib/types/types/enum.rb
sorbet-runtime-0.5.11150 lib/types/types/enum.rb
study_line-0.1.6 vendor/bundle/ruby/3.2.0/gems/sorbet-runtime-0.5.11108/lib/types/types/enum.rb
study_line-0.1.6 vendor/bundle/ruby/3.2.0/gems/sorbet-runtime-0.5.11104/lib/types/types/enum.rb
sorbet-runtime-0.5.11148 lib/types/types/enum.rb
sorbet-runtime-0.5.11147 lib/types/types/enum.rb
study_line-0.1.5 vendor/bundle/ruby/3.2.0/gems/sorbet-runtime-0.5.11108/lib/types/types/enum.rb
study_line-0.1.5 vendor/bundle/ruby/3.2.0/gems/sorbet-runtime-0.5.11104/lib/types/types/enum.rb
study_line-0.1.4 vendor/bundle/ruby/3.2.0/gems/sorbet-runtime-0.5.11104/lib/types/types/enum.rb
study_line-0.1.4 vendor/bundle/ruby/3.2.0/gems/sorbet-runtime-0.5.11108/lib/types/types/enum.rb
sorbet-runtime-0.5.11146 lib/types/types/enum.rb
study_line-0.1.3 vendor/bundle/ruby/3.2.0/gems/sorbet-runtime-0.5.11104/lib/types/types/enum.rb