From 260f9ae4efc0a25eae682ef6b1ca4310fe6ca5d7 Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Thu, 5 Apr 2012 18:02:16 +0200 Subject: [PATCH] one way to avoid autosave --- .../locomotive/extensions/page/fullpath.rb | 11 ++--- app/models/locomotive/extensions/page/tree.rb | 6 +-- lib/locomotive/mongoid/patches.rb | 42 +++++++++---------- 3 files changed, 30 insertions(+), 29 deletions(-) diff --git a/app/models/locomotive/extensions/page/fullpath.rb b/app/models/locomotive/extensions/page/fullpath.rb index de6e01d9..03061f59 100644 --- a/app/models/locomotive/extensions/page/fullpath.rb +++ b/app/models/locomotive/extensions/page/fullpath.rb @@ -16,7 +16,7 @@ module Locomotive before_validation :get_wildcards_from_parent before_validation :add_slug_to_wildcards before_save :build_fullpath - before_save :set_children_autosave + # before_save :set_children_autosave # before_rearrange :foo #propagate_fullpath_changes # after_save :propagate_fullpath_changes @@ -62,10 +62,10 @@ module Locomotive protected - def set_children_autosave - @autosave_for_children = !must_propagate_fullpath_changes? - true - end + # def set_children_autosave + # @autosave_for_children = !must_propagate_fullpath_changes? + # true + # end def get_wildcards_from_parent return true if self.parent.nil? @@ -81,6 +81,7 @@ module Locomotive end def add_slug_to_wildcards + puts "[add_slug_to_wildcards] #{self.slug} / #{self.wildcard?}" (self.wildcards ||= []) << self.slug if self.wildcard? end diff --git a/app/models/locomotive/extensions/page/tree.rb b/app/models/locomotive/extensions/page/tree.rb index ec765428..ff60d7eb 100644 --- a/app/models/locomotive/extensions/page/tree.rb +++ b/app/models/locomotive/extensions/page/tree.rb @@ -74,9 +74,9 @@ module Locomotive end - def autosave_for_children? - @autosave_for_children != false - end + # def autosave_for_children? + # @autosave_for_children != false + # end # Returns the children of this node but with the minimal set of required attributes # diff --git a/lib/locomotive/mongoid/patches.rb b/lib/locomotive/mongoid/patches.rb index a2e43b4f..dfc23976 100644 --- a/lib/locomotive/mongoid/patches.rb +++ b/lib/locomotive/mongoid/patches.rb @@ -12,27 +12,27 @@ module Mongoid#:nodoc: end end - module Relations #:nodoc: - module AutoSave - module ClassMethods #:nodoc: - def autosave(metadata) - if metadata.autosave? - set_callback :save, :after do |document| - relation = document.send(metadata.name) - - return true if document.try(:"autosave_for_#{metadata.name}?") == false # FIXME (Didier L.) add more control on the document side - - if relation - (relation.do_or_do_not(:in_memory) || Array.wrap(relation)).each do |doc| - doc.save - end - end - end - end - end - end - end - end + # module Relations #:nodoc: + # module AutoSave + # module ClassMethods #:nodoc: + # def autosave(metadata) + # if metadata.autosave? + # set_callback :save, :after do |document| + # relation = document.send(metadata.name) + # + # return true if document.try(:"autosave_for_#{metadata.name}?") == false # FIXME (Didier L.) add more control on the document side + # + # if relation + # (relation.do_or_do_not(:in_memory) || Array.wrap(relation)).each do |doc| + # doc.save + # end + # end + # end + # end + # end + # end + # end + # end module Fields #:nodoc: module Internal #:nodoc: