Permalink
Browse files

Fixing trackable for callbacks

  • Loading branch information...
1 parent a9ee17b commit 5e19608da96e9d00abcd33dc8ce792e839a5f4a5 @callumj callumj committed Feb 16, 2012
Showing with 13 additions and 1 deletion.
  1. +8 −0 lib/mongoid/history/trackable.rb
  2. +4 −0 lib/mongoid/history/tracker.rb
  3. +1 −1 mongoid-history.gemspec
@@ -110,6 +110,14 @@ def _redo(modifier, options_or_version=nil)
self.write_attributes(redo_attr, false) # guard_protected_attributes = false
end
end
+
+ def hydrated_from_hash?
+ !(defined?(@hydrated_from_hash).nil?) && @hydrated_from_hash.eql?(true)
+ end
+
+ def hydrated_from_hash!
+ @hydrated_from_hash = true
+ end
##
# PRIVATE
@@ -86,6 +86,8 @@ def trackable_root_from_hash
return unless root_name && root_hash
@trackable_root_from_hash ||=
Mongoid::Factory.from_db(doc_name.classify.constantize, root_hash) rescue nil
+ @trackable_root_from_hash.hydrated_from_hash! if !(defined?(@trackable_root_from_hash).nil?) && @trackable_root_from_hash.respond_to?(:hydrated_from_hash!)
+ @trackable_root_from_hash
end
def trackable
@@ -102,6 +104,8 @@ def trackable_from_hash
klass = doc_name.classify.constantize
@trackable_from_hash ||=
klass.instantiate(doc_hash) rescue nil
+ @trackable_from_hash.hydrated_from_hash! if !(defined?(@trackable_from_hash).nil?) && @trackable_from_hash.respond_to?(:hydrated_from_hash!)
+ @trackable_from_hash
end
def trackable_parents
@@ -5,7 +5,7 @@
Gem::Specification.new do |s|
s.name = %q{mongoid-history}
- s.version = "0.1.4"
+ s.version = "0.1.6"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = [%q{Aaron Qian}, %q{Justin Grimes}]

0 comments on commit 5e19608

Please sign in to comment.