Class: Dry::Data::Enum
- Inherits:
-
Object
- Object
- Dry::Data::Enum
- Includes:
- Decorator
- Defined in:
- lib/dry/data/enum.rb
Instance Attribute Summary collapse
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Attributes included from Decorator
Instance Method Summary collapse
- #call(input) ⇒ Object (also: #[])
-
#initialize(type, options) ⇒ Enum
constructor
A new instance of Enum.
Methods included from Decorator
#constructor, #respond_to_missing?, #valid?, #with
Constructor Details
#initialize(type, options) ⇒ Enum
Returns a new instance of Enum.
10 11 12 13 14 |
# File 'lib/dry/data/enum.rb', line 10 def initialize(type, ) super @values = .fetch(:values).freeze @values.each(&:freeze) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Dry::Data::Decorator
Instance Attribute Details
#values ⇒ Object (readonly)
Returns the value of attribute values.
8 9 10 |
# File 'lib/dry/data/enum.rb', line 8 def values @values end |
Instance Method Details
#call(input) ⇒ Object Also known as: []
16 17 18 19 20 |
# File 'lib/dry/data/enum.rb', line 16 def call(input) case input when Fixnum then type[values[input]] else type[input] end end |