Sha256: 11a3fee2d0208dac0ef5739c7b8a779f401cd9df1e2364a3ef6f1a7dbacee6be

Contents?: true

Size: 789 Bytes

Versions: 2

Compression:

Stored size: 789 Bytes

Contents

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

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

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

        def serialize(object)
          "#{PREFIX}_#{object.class}_#{object.id}"
        end
        
        def deserialize(object)
          match = MATCHER.match(object)
          match[1].constantize.find_by_id(match[2])
        end
      end
    end
  end
end

ResqueDelayable::ACTIVE_SERIALIZERS << ResqueDelayable::Serializer::ActiveRecordSerializer
ActiveRecord::Base.send :include, ResqueDelayable

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
resque-delayable-1.0.1 lib/resque-delayable/serializer/active_record_serializer.rb
resque-delayable-1.0.0 lib/resque-delayable/serializer/active_record_serializer.rb