Sha256: c28145e22407c9df2d362831c8af7476655559563cc2c0818f3765dc9b203863

Contents?: true

Size: 778 Bytes

Versions: 3

Compression:

Stored size: 778 Bytes

Contents

module ResqueDelayable
  module Serializer
    class MongoidSerializer
      PREFIX = "Mongoid"
      MATCHER = Regexp.new("^#{PREFIX}_([^_]+)_([^_]+)$")

      class << self
        def serialize_match(object)
          object.is_a?(Mongoid::Document)
        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(id)
        end
      end
    end
  end
end

ResqueDelayable::ACTIVE_SERIALIZERS << ResqueDelayable::Serializer::MongoidSerializer
Mongoid::Document.send :include, ResqueDelayable

Version data entries

3 entries across 3 versions & 1 rubygems

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