Class: ReeEnum::StringValueEnumMapper
- Inherits:
-
BaseEnumMapper
- Object
- ReeMapper::AbstractType
- BaseEnumMapper
- ReeEnum::StringValueEnumMapper
- Defined in:
- lib/ree_lib/packages/ree_enum/package/ree_enum/string_value_enum_mapper.rb
Instance Attribute Summary
Attributes inherited from BaseEnumMapper
Instance Method Summary collapse
Methods inherited from BaseEnumMapper
#db_dump, #db_load, #initialize
Constructor Details
This class inherits a constructor from ReeEnum::BaseEnumMapper
Instance Method Details
#cast(value) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ree_lib/packages/ree_enum/package/ree_enum/string_value_enum_mapper.rb', line 11 def cast(value) enum_value = case value when String @enum.get_values.by_value(value) when ReeEnum::Value @enum.get_values.each.find { _1 == value } end if enum_value.nil? raise ReeMapper::CoercionError.new("should be one of #{enum_inspection}, got `#{truncate(value.inspect)}`") end enum_value end |
#serialize(value) ⇒ Object
6 7 8 |
# File 'lib/ree_lib/packages/ree_enum/package/ree_enum/string_value_enum_mapper.rb', line 6 def serialize(value) value.value end |