Sha256: 01036b7a21aabe9f65274dc61732f12bfcfee0ad1730e0469e73cd02902f52a0

Contents?: true

Size: 792 Bytes

Versions: 1

Compression:

Stored size: 792 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

1 entries across 1 versions & 1 rubygems

Version Path
resque-delayable-1.0.2 lib/resque-delayable/serializer/active_record_serializer.rb