Class: ActiveRecord::Base

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

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) yaml_new(klass, tag, val)



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

- (Object) encode_with(coder)

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

- (Object) to_yaml_properties



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

def to_yaml_properties
  ['@attributes']
end