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.
Check that ActiveRecord exists before overriding methods.
- Loading branch information
Showing
2 changed files
with
22 additions
and
18 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 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 |
---|---|---|
@@ -1,17 +1,19 @@ | ||
class ActiveRecord::Base | ||
yaml_as "tag:ruby.yaml.org,2002:ActiveRecord" | ||
if defined?(ActiveRecord) | ||
class ActiveRecord::Base | ||
yaml_as "tag:ruby.yaml.org,2002:ActiveRecord" | ||
|
||
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]) } | ||
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 | ||
end | ||
rescue ActiveRecord::RecordNotFound | ||
raise Delayed::DeserializationError | ||
end | ||
|
||
def to_yaml_properties | ||
['@attributes'] | ||
def to_yaml_properties | ||
['@attributes'] | ||
end | ||
end | ||
end | ||
end |