Class Psych::Visitors::ToRuby
In: lib/delayed/psych_ext.rb
Parent: Object

Methods

Public Instance methods

[Source]

    # File lib/delayed/psych_ext.rb, line 66
66:       def resolve_class_with_constantize(klass_name)
67:         klass_name.constantize
68:       rescue
69:         resolve_class_without_constantize(klass_name)
70:       end

[Source]

    # File lib/delayed/psych_ext.rb, line 33
33:       def visit_Psych_Nodes_Mapping_with_class(object)
34:         return revive(Psych.load_tags[object.tag], object) if Psych.load_tags[object.tag]
35: 
36:         case object.tag
37:         when /^!ruby\/class:?(.*)?$/
38:           resolve_class $1
39:         when /^!ruby\/ActiveRecord:(.+)$/
40:           klass = resolve_class($1)
41:           payload = Hash[*object.children.map { |c| accept c }]
42:           id = payload["attributes"][klass.primary_key]
43:           begin
44:             if ActiveRecord::VERSION::MAJOR == 3
45:               klass.unscoped.find(id)
46:             else # Rails 2
47:               klass.with_exclusive_scope { klass.find(id) }
48:             end
49:           rescue ActiveRecord::RecordNotFound
50:             raise Delayed::DeserializationError
51:           end
52:         when /^!ruby\/Mongoid:(.+)$/
53:           klass = resolve_class($1)
54:           payload = Hash[*object.children.map { |c| accept c }]
55:           begin
56:             klass.find(payload["attributes"]["_id"])
57:           rescue Mongoid::Errors::DocumentNotFound
58:             raise Delayed::DeserializationError
59:           end
60:         else
61:           visit_Psych_Nodes_Mapping_without_class(object)
62:         end
63:       end

[Validate]