mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Not sure what to do with this so it's here if someone wants to use it, #152
This commit is contained in:
parent
e65efd5f0a
commit
c96635ffbf
1 changed files with 21 additions and 0 deletions
21
lib/sidekiq/yaml_patch.rb
Normal file
21
lib/sidekiq/yaml_patch.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
# YAML marshalling of instances can fail in some circumstances,
|
||||
# e.g. when the instance has a handle to a Proc. This monkeypatch limits
|
||||
# the YAML serialization to just AR's internal @attributes hash.
|
||||
# The paperclip gem litters AR instances with Procs, for instance.
|
||||
#
|
||||
# Courtesy of @ryanlecompte https://gist.github.com/007b88ae90372d1a3321
|
||||
#
|
||||
|
||||
if defined?(::ActiveRecord)
|
||||
class ActiveRecord::Base
|
||||
yaml_as "tag:ruby.yaml.org,2002:ActiveRecord"
|
||||
|
||||
def self.yaml_new(klass, tag, val)
|
||||
klass.unscoped.find(val['attributes'][klass.primary_key])
|
||||
end
|
||||
|
||||
def to_yaml_properties
|
||||
['@attributes']
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue