Class: DataMapper::Is::Serialized::Filters::ModelSerializeFilter
- Inherits:
-
SerializeFilter
- Object
- SerializeFilter
- DataMapper::Is::Serialized::Filters::ModelSerializeFilter
- Defined in:
- lib/dm-is-serialized/is/filters.rb
Overview
serialize: :product => product_id
Instance Attribute Summary
Attributes inherited from SerializeFilter
Instance Method Summary collapse
-
#deserialize(id) ⇒ Object
product_id => id.
- #model ⇒ Object
-
#serialize(record) ⇒ Object
serialize(:product).
Methods inherited from SerializeFilter
Instance Method Details
#deserialize(id) ⇒ Object
product_id => id
41 42 43 44 |
# File 'lib/dm-is-serialized/is/filters.rb', line 41 def deserialize(id) ids = id.split("|") model.get(*ids) end |
#model ⇒ Object
46 47 48 |
# File 'lib/dm-is-serialized/is/filters.rb', line 46 def model Object.const_get(@name.to_s.camel_case) end |
#serialize(record) ⇒ Object
serialize(:product)
33 34 35 36 37 38 |
# File 'lib/dm-is-serialized/is/filters.rb', line 33 def serialize(record) keys = model.key.map { |property| property.name } raise "Record can't be nil (#{model} with keys #{keys})" if record.nil? values = keys.map { |key| record.send(key) } values.length.eql?(1) ? values.first : values.join("|") end |