Class: Redistry::Serializers::ActiveRecord

Inherits:
Object
  • Object
show all
Defined in:
lib/redistry/serializers/activerecord.rb

Instance Method Summary collapse

Instance Method Details

#deserialize(klass, *objs) ⇒ Object



8
9
10
11
12
# File 'lib/redistry/serializers/activerecord.rb', line 8

def deserialize(klass, *objs)
  ids = objs.flatten
  ar_objects = klass.find(objs.flatten).inject({}) { |h,o| h[o.id.to_s] = o; h }
  ids.map { |i| ar_objects[i.to_s] }
end

#serialize(klass, *objs) ⇒ Object



4
5
6
# File 'lib/redistry/serializers/activerecord.rb', line 4

def serialize(klass, *objs)
  objs.flatten.map(&:id)
end