Module: RPCMapper::Serialization::ClassMethods

Defined in:
lib/rpc_mapper/serialization.rb

Instance Method Summary collapse

Instance Method Details

#serialize(fields) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rpc_mapper/serialization.rb', line 7

def serialize(fields)
  [*fields].each do |field|
    serialized_attributes << field

    define_method("deserialize_#{field}") do
      YAML.load(self[field]) rescue self[field]
    end

    alias_method "#{field}_raw", field
    alias_method field, "deserialize_#{field}"

    set_serialize_writers(field) if self.write_adapter

  end
end

#set_serialize_writers(field) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/rpc_mapper/serialization.rb', line 23

def set_serialize_writers(field)
  define_method("serialize_#{field}") do |value|
    self[field] = value.to_yaml
  end

  alias_method "#{field}_raw=", "#{field}="
  alias_method "#{field}=", "serialize_#{field}"
end