Module: RecordMarshal

Defined in:
lib/tiny_cache/record_marshal.rb

Class Method Summary collapse

Class Method Details

.dump(record) ⇒ Object

dump ActiveRecord instace with only attributes. [“User”,

{"id"=>30,
"email"=>"[email protected]",
"created_at"=>2012-07-25 18:25:57 UTC
}

]



12
13
14
15
16
17
# File 'lib/tiny_cache/record_marshal.rb', line 12

def dump(record)
  [
   record.class.name,
   record.instance_variable_get(:@attributes)
  ]
end

.load(serialized) ⇒ Object

load a cached record



20
21
22
23
24
25
# File 'lib/tiny_cache/record_marshal.rb', line 20

def load(serialized)
  return unless serialized
  record = serialized[0].constantize.allocate
  record.init_with('attributes' => serialized[1])
  record
end