Module: DataMapper::Is::Serialized::ClassMethods

Includes:
Filters
Defined in:
lib/dm-is-serialized/is/serialized.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#serialized_propertiesObject

Returns the value of attribute serialized_properties.



20
21
22
# File 'lib/dm-is-serialized/is/serialized.rb', line 20

def serialized_properties
  @serialized_properties
end

Instance Method Details

#deserialize(data) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/dm-is-serialized/is/serialized.rb', line 40

def deserialize(data)
  params = Hash.new
  data.split(",").each_with_index do |data, index|
    property_name, filter_class = self.serialized_properties[index]
    filter = filter_class.new
    filter.name = property_name
    value  = filter.deserialize(data)
    #value.nil? ? raise(TypeError) : value
    params[property_name] = value
  end
  return self.new(params)
end

#serialize_properties(*properties) ⇒ Object

serialize_properties :product, :count serialize_properties :product, :count, GeneralSerializeFilter



31
32
33
34
35
36
37
38
# File 'lib/dm-is-serialized/is/serialized.rb', line 31

def serialize_properties(*properties)
  self.serialized_properties ||= Array.new
  filter = properties.last.class.eql?(Class) ? properties.pop : GeneralSerializeFilter
  properties.each do |property|
    self.serialized_properties.push([property, filter])
  end
  self.serialized_properties.uniq!
end

#serialize_property(property, filter = GeneralSerializeFilter) ⇒ Object

serialize_property :size, BooleanSerializedFilter



23
24
25
26
27
# File 'lib/dm-is-serialized/is/serialized.rb', line 23

def serialize_property(property, filter = GeneralSerializeFilter)
  self.serialized_properties ||= Array.new
  self.serialized_properties.push([property, filter])
  self.serialized_properties.uniq!
end