forked from collectiveidea/delayed_job
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
constantize objects when deserializing so that ActiveSupport can atte…
…mpt its auto loading magic Closes collectiveidea#65
- Loading branch information
Showing
8 changed files
with
74 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# These extensions allow properly serializing and autoloading of | ||
# Classes, Modules and Structs | ||
|
||
require 'yaml' | ||
|
||
class Module | ||
yaml_as "tag:ruby.yaml.org,2002:module" | ||
|
||
def self.yaml_new(klass, tag, val) | ||
val.constantize | ||
end | ||
|
||
def to_yaml( opts = {} ) | ||
YAML::quick_emit( nil, opts ) { |out| | ||
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 | ||
yaml_as "tag:ruby.yaml.org,2002:class" | ||
remove_method :to_yaml # use Module's to_yaml | ||
end | ||
|
||
class Struct | ||
def self.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 | ||
"Struct::#{ name }" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Make sure this file does not get required manually | ||
module Autoloaded | ||
class Clazz | ||
def perform | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Make sure this file does not get required manually | ||
module Autoloaded | ||
class Struct < ::Struct.new(nil) | ||
def perform | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters