Class: ActiveRecord::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/delayed/serialization/active_record.rb,
lib/delayed/psych_ext.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.yaml_new(klass, tag, val) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/delayed/serialization/active_record.rb', line 5

def self.yaml_new(klass, tag, val)
  if ActiveRecord::VERSION::MAJOR == 3
    klass.unscoped.find(val['attributes'][klass.primary_key])
  else # Rails 2
    klass.with_exclusive_scope { klass.find(val['attributes'][klass.primary_key]) }
  end
rescue ActiveRecord::RecordNotFound
  raise Delayed::DeserializationError, "ActiveRecord::RecordNotFound, class: #{klass} , primary key: #{val['attributes'][klass.primary_key]} "
end

Instance Method Details

#encode_with(coder) ⇒ Object

serialize to YAML



4
5
6
7
# File 'lib/delayed/psych_ext.rb', line 4

def encode_with(coder)
  coder["attributes"] = @attributes
  coder.tag = ['!ruby/ActiveRecord', self.class.name].join(':')
end

#to_yaml_propertiesObject



15
16
17
# File 'lib/delayed/serialization/active_record.rb', line 15

def to_yaml_properties
  ['@attributes']
end