Class: ActiveRecord::Base

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

Direct Known Subclasses

TaskDependency

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
14
# File 'lib/queue_dispatcher/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 QueueDispatcher::DeserializationError, "ActiveRecord::RecordNotFound, class: #{klass} , primary key: #{val['attributes'][klass.primary_key]} "
  '----- QueueDispatcher::DeserializationError -----'
end

Instance Method Details

#encode_with(coder) ⇒ Object

serialize to YAML



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

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

#to_yaml_propertiesObject



16
17
18
# File 'lib/queue_dispatcher/serialization/active_record.rb', line 16

def to_yaml_properties
  ['@attributes']
end