Module: Resque::Mailer::Serializers::ActiveRecordSerializer

Extended by:
ActiveRecordSerializer
Included in:
ActiveRecordSerializer
Defined in:
lib/resque_mailer/serializers/active_record_serializer.rb

Instance Method Summary collapse

Instance Method Details

#deserialize(data) ⇒ Object


17
18
19
20
21
22
23
24
25
# File 'lib/resque_mailer/serializers/active_record_serializer.rb', line 17

def deserialize(data)
  data.map do |arg|
    if arg.is_a?(Hash) && arg.has_key?("class_name") && arg.has_key?("id")
      arg["class_name"].constantize.find(arg["id"])
    else
      arg
    end
  end
end

#serialize(*args) ⇒ Object


7
8
9
10
11
12
13
14
15
# File 'lib/resque_mailer/serializers/active_record_serializer.rb', line 7

def serialize(*args)
  args.map do |arg|
    if arg.is_a?(ActiveRecord::Base)
      { "class_name" => arg.class.name, "id" => arg.id }
    else
      arg
    end
  end
end