Class: ResqueDelayable::Serializer::ActiveRecordSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/resque-delayable/serializer/active_record_serializer.rb

Constant Summary collapse

PREFIX =
"ActiveRecord"
MATCHER =
Regexp.new("^#{PREFIX}_(\\w+)_(\\d+)$")

Class Method Summary collapse

Class Method Details

.deserialize(object) ⇒ Object



20
21
22
23
# File 'lib/resque-delayable/serializer/active_record_serializer.rb', line 20

def deserialize(object)
  match = MATCHER.match(object)
  match[1].constantize.find_by_id(match[2])
end

.deserialize_match(object) ⇒ Object



12
13
14
# File 'lib/resque-delayable/serializer/active_record_serializer.rb', line 12

def deserialize_match(object)
  object.class == String && MATCHER.match(object)
end

.serialize(object) ⇒ Object



16
17
18
# File 'lib/resque-delayable/serializer/active_record_serializer.rb', line 16

def serialize(object)
  "#{PREFIX}_#{object.class}_#{object.id}"
end

.serialize_match(object) ⇒ Object



8
9
10
# File 'lib/resque-delayable/serializer/active_record_serializer.rb', line 8

def serialize_match(object)
  object.is_a?(ActiveRecord::Base)
end