Skip to content

Commit

Permalink
Revert serialization refactoring that had some major issues
Browse files Browse the repository at this point in the history
This reverts commit cbde340.
  • Loading branch information
bkeepers committed Nov 15, 2010
1 parent f99439a commit ffd1173
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lib/delayed/backend/base.rb
Expand Up @@ -68,7 +68,7 @@ def name

def payload_object=(object)
@payload_object = object
self.handler = object.to_delayed_yaml
self.handler = object.to_yaml
end

def payload_object
Expand Down
19 changes: 7 additions & 12 deletions lib/delayed/serialization/active_record.rb
@@ -1,18 +1,13 @@
class ActiveRecord::Base
def to_delayed_yaml( opts = {} )
YAML::quick_emit( self, opts ) do |out|
out.map("tag:delayed_job.com,2010:ActiveRecord:#{self.class.name}", to_yaml_style) do |map|
map.add('id', id)
end
end
end
end
yaml_as "tag:ruby.yaml.org,2002:ActiveRecord"

YAML.add_domain_type('delayed_job.com,2010', 'ActiveRecord') do |tag, value|
begin
type, model = YAML.read_type_class(tag, Kernel)
model.find(value['id'])
def self.yaml_new(klass, tag, val)
klass.find(val['attributes']['id'])
rescue ActiveRecord::RecordNotFound
raise Delayed::DeserializationError
end

def to_yaml_properties
['@attributes']
end
end
10 changes: 2 additions & 8 deletions lib/delayed/yaml_ext.rb
Expand Up @@ -15,14 +15,14 @@ def to_yaml( opts = {} )
out.scalar(taguri, self.name, :plain)
}
end

def yaml_tag_read_class(name)
# Constantize the object so that ActiveSupport can attempt
# its auto loading magic. Will raise LoadError if not successful.
name.constantize
name
end

end

class Class
Expand All @@ -38,9 +38,3 @@ def self.yaml_tag_read_class(name)
"Struct::#{ name }"
end
end

class Object
def to_delayed_yaml
to_yaml
end
end

0 comments on commit ffd1173

Please sign in to comment.