Sha256: 5eb5659451b07c5b8b5e55002a046152eddca4995bf304ab279a0ff4a4b6bad1

Contents?: true

Size: 599 Bytes

Versions: 6

Compression:

Stored size: 599 Bytes

Contents

require 'apartment/delayed_job/enqueue'

module Apartment
  module Delayed

    # Mix this module into any ActiveRecord model that gets serialized by DJ
    module Requirements
      attr_accessor :database

      def self.included(klass)
        klass.after_find :set_database      # set db when records are pulled so they deserialize properly
        klass.before_save :set_database     # set db before records are saved so that they also get deserialized properly
      end

    private

      def set_database
        @database = Apartment::Database.current_database
      end

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
apartment-0.22.1 lib/apartment/delayed_job/requirements.rb
apartment-0.22.0 lib/apartment/delayed_job/requirements.rb
apartment-0.21.1 lib/apartment/delayed_job/requirements.rb
apartment-0.21.0 lib/apartment/delayed_job/requirements.rb
apartment-0.20.0 lib/apartment/delayed_job/requirements.rb
apartment-0.14.2 lib/apartment/delayed_job/requirements.rb