Sha256: d135cb0a518441809a159c355954271509bb3b1c262b62278129ae2e0399ebfa

Contents?: true

Size: 943 Bytes

Versions: 14

Compression:

Stored size: 943 Bytes

Contents

module ActiveRecord
  class Base

    # Overriding Delayed Job's monkey_patch of ActiveRecord so that it works with Apartment
    yaml_as "tag:ruby.yaml.org,2002:ActiveRecord"

    def self.yaml_new(klass, tag, val)
      Apartment::Database.process(val['database']) do
        klass.find(val['attributes']['id'])
      end
    rescue ActiveRecord::RecordNotFound => e
      raise Delayed::DeserializationError,  e.message
    end

    # Rails > 3.0 now uses encode_with to determine what to encode with yaml
    # @override to include database attribute
    def encode_with_with_database(coder)
      coder['database'] = @database if @database.present?
      encode_with_without_database(coder)
    end
    alias_method_chain :encode_with, :database

    # Remain backwards compatible with old yaml serialization
    def to_yaml_properties
      ['@attributes', '@database']    # add in database attribute for serialization
    end

  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
apartment-0.22.1 lib/apartment/delayed_job/syck_ext.rb
apartment-0.22.0 lib/apartment/delayed_job/syck_ext.rb
apartment-0.21.1 lib/apartment/delayed_job/syck_ext.rb
apartment-0.21.0 lib/apartment/delayed_job/syck_ext.rb
apartment-0.20.0 lib/apartment/delayed_job/syck_ext.rb
apartment-0.19.0 lib/apartment/delayed_job/active_record.rb
apartment-0.18.0 lib/apartment/delayed_job/active_record.rb
apartment-0.17.3 lib/apartment/delayed_job/active_record.rb
apartment-0.17.2 lib/apartment/delayed_job/active_record.rb
apartment-0.17.1 lib/apartment/delayed_job/active_record.rb
apartment-0.17.0 lib/apartment/delayed_job/active_record.rb
apartment-0.16.0 lib/apartment/delayed_job/active_record.rb
apartment-0.15.0 lib/apartment/delayed_job/active_record.rb
apartment-0.14.4 lib/apartment/delayed_job/active_record.rb