Class: ReeEnum::BaseEnumMapper

Inherits:
ReeMapper::AbstractType show all
Defined in:
lib/ree_lib/packages/ree_enum/package/ree_enum/base_enum_mapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(enum) ⇒ BaseEnumMapper

Returns a new instance of BaseEnumMapper.



7
8
9
# File 'lib/ree_lib/packages/ree_enum/package/ree_enum/base_enum_mapper.rb', line 7

def initialize(enum)
  @enum = enum
end

Instance Attribute Details

#enumObject (readonly)

Returns the value of attribute enum.



5
6
7
# File 'lib/ree_lib/packages/ree_enum/package/ree_enum/base_enum_mapper.rb', line 5

def enum
  @enum
end

Instance Method Details

#db_dump(value) ⇒ Object



12
13
14
# File 'lib/ree_lib/packages/ree_enum/package/ree_enum/base_enum_mapper.rb', line 12

def db_dump(value)
  value.mapped_value
end

#db_load(value) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/ree_lib/packages/ree_enum/package/ree_enum/base_enum_mapper.rb', line 17

def db_load(value)
  enum_val = @enum.get_values.by_mapped_value(value)

  if !enum_val
    raise ReeMapper::CoercionError.new("should be one of #{enum_inspection}, got `#{truncate(value.inspect)}`")
  end

  enum_val
end