Class: ActiveRecord::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/delayed/yaml_extensions.rb,
lib/delayed/backend/active_record.rb

Overview

Tell YAML how to intelligently load ActiveRecord objects, using the database rather than just serializing their attributes to the YAML. This ensures the object is up to date when we use it in the job.

Direct Known Subclasses

Delayed::Backend::ActiveRecord::Job

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.load_for_delayed_job(id) ⇒ Object



2
3
4
5
6
7
8
# File 'lib/delayed/backend/active_record.rb', line 2

def self.load_for_delayed_job(id)
  if id
    find(id)
  else
    super
  end
end

Instance Method Details

#encode_with(coder) ⇒ Object



21
22
23
24
25
26
# File 'lib/delayed/yaml_extensions.rb', line 21

def encode_with(coder)
  if id.nil?
    raise("Can't serialize unsaved ActiveRecord object for delayed job: #{self.inspect}")
  end
  coder.scalar("!ruby/ActiveRecord:#{self.class.name}", id.to_s)
end