Class: T::Types::Enum
- 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
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
- #build_type ⇒ Object
-
#describe_obj(obj) ⇒ Object
overrides Base.
-
#initialize(values) ⇒ Enum
constructor
A new instance of Enum.
-
#name ⇒ Object
overrides Base.
-
#valid?(obj) ⇒ Boolean
overrides Base.
Methods included from 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
#values ⇒ Object (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
#build_type ⇒ Object
15 16 17 |
# File 'lib/types/types/enum.rb', line 15 def build_type nil end |
#describe_obj(obj) ⇒ Object
overrides Base
40 41 42 |
# File 'lib/types/types/enum.rb', line 40 def describe_obj(obj) obj.inspect end |
#name ⇒ Object
overrides Base
35 36 37 |
# File 'lib/types/types/enum.rb', line 35 def name @name ||= "T.deprecated_enum([#{@values.map(&:inspect).sort.join(', ')}])" end |
#valid?(obj) ⇒ Boolean
overrides Base
20 21 22 |
# File 'lib/types/types/enum.rb', line 20 def valid?(obj) @values.member?(obj) end |