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.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.load_for_delayed_job(id) ⇒ Object



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

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

Instance Method Details

#encode_with(coder) ⇒ Object



23
24
25
26
27
28
# File 'lib/delayed/yaml_extensions.rb', line 23

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