Class: Enumerize::ActiveModelAttributesSupport::Type

Inherits:
ActiveModel::Type::Value
  • Object
show all
Defined in:
lib/enumerize/activemodel.rb

Instance Method Summary collapse

Constructor Details

#initialize(attr) ⇒ Type

Returns a new instance of Type.


33
34
35
# File 'lib/enumerize/activemodel.rb', line 33

def initialize(attr)
  @attr = attr
end

Instance Method Details

#deserialize(value) ⇒ Object


42
43
44
# File 'lib/enumerize/activemodel.rb', line 42

def deserialize(value)
  @attr.find_value(value)
end

#serialize(value) ⇒ Object


37
38
39
40
# File 'lib/enumerize/activemodel.rb', line 37

def serialize(value)
  v = @attr.find_value(value)
  v && v.value
end

#typeObject


29
30
31
# File 'lib/enumerize/activemodel.rb', line 29

def type
  :enumerize
end