Class: T::Types::Enum

Inherits:
Base
  • Object
show all
Extended by:
Sig
Defined in:
lib/types/types/enum.rb

Overview

validates that the provided value is within a given set/enum

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Sig

sig

Methods inherited from Base

#==, #error_message_for_obj, #error_message_for_obj_recursive, #hash, method_added, #recursively_valid?, #subtype_of?, #to_s, #validate!

Constructor Details

#initialize(values) ⇒ Enum

Returns a new instance of Enum.



11
12
13
# File 'lib/types/types/enum.rb', line 11

def initialize(values)
  @values = values
end

Instance Attribute Details

#valuesObject (readonly)

Returns the value of attribute values.



9
10
11
# File 'lib/types/types/enum.rb', line 9

def values
  @values
end

Instance Method Details

#describe_obj(obj) ⇒ Object

overrides Base



36
37
38
# File 'lib/types/types/enum.rb', line 36

def describe_obj(obj)
  obj.inspect
end

#nameObject

overrides Base



31
32
33
# File 'lib/types/types/enum.rb', line 31

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

#valid?(obj) ⇒ Boolean

overrides Base

Returns:



16
17
18
# File 'lib/types/types/enum.rb', line 16

def valid?(obj)
  @values.member?(obj)
end