Class: Literal::Rails::EnumType

Inherits:
ActiveModel::Type::Value
  • Object
show all
Defined in:
lib/literal/rails/enum_type.rb

Instance Method Summary collapse

Constructor Details

#initialize(enum) ⇒ EnumType

Returns a new instance of EnumType.



4
5
6
7
# File 'lib/literal/rails/enum_type.rb', line 4

def initialize(enum)
  @enum = enum
  super()
end

Instance Method Details

#cast(value) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/literal/rails/enum_type.rb', line 13

def cast(value)
  case value
  when nil
    nil
  else
    @enum.coerce(value)
  end
end

#deserialize(value) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/literal/rails/enum_type.rb', line 31

def deserialize(value)
  case value
  when nil
    nil
  else
    @enum.coerce(value)
  end
end

#serialize(value) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/literal/rails/enum_type.rb', line 22

def serialize(value)
  case value
  when nil
    nil
  else
    @enum.coerce(value).value
  end
end

#typeObject



9
10
11
# File 'lib/literal/rails/enum_type.rb', line 9

def type
  :literal_enum
end