Class: ReeEnum::IntegerValueEnumMapper
- Inherits:
-
BaseEnumMapper
- Object
- ReeMapper::AbstractType
- BaseEnumMapper
- ReeEnum::IntegerValueEnumMapper
- Defined in:
- lib/ree_lib/packages/ree_enum/package/ree_enum/integer_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 25 26 27 28 29 |
# File 'lib/ree_lib/packages/ree_enum/package/ree_enum/integer_value_enum_mapper.rb', line 11 def cast(value) enum_value = case value when Integer @enum.get_values.by_value(value) when String value = Integer(value, exception: false) if !value.nil? @enum.get_values.by_value(value) end 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/integer_value_enum_mapper.rb', line 6 def serialize(value) value.value end |