one way to avoid autosave

This commit is contained in:
Didier Lafforgue 2012-04-05 18:02:16 +02:00
parent 64ea41cbcd
commit 260f9ae4ef
3 changed files with 30 additions and 29 deletions

View File

@ -16,7 +16,7 @@ module Locomotive
before_validation :get_wildcards_from_parent before_validation :get_wildcards_from_parent
before_validation :add_slug_to_wildcards before_validation :add_slug_to_wildcards
before_save :build_fullpath before_save :build_fullpath
before_save :set_children_autosave # before_save :set_children_autosave
# before_rearrange :foo #propagate_fullpath_changes # before_rearrange :foo #propagate_fullpath_changes
# after_save :propagate_fullpath_changes # after_save :propagate_fullpath_changes
@ -62,10 +62,10 @@ module Locomotive
protected protected
def set_children_autosave # def set_children_autosave
@autosave_for_children = !must_propagate_fullpath_changes? # @autosave_for_children = !must_propagate_fullpath_changes?
true # true
end # end
def get_wildcards_from_parent def get_wildcards_from_parent
return true if self.parent.nil? return true if self.parent.nil?
@ -81,6 +81,7 @@ module Locomotive
end end
def add_slug_to_wildcards def add_slug_to_wildcards
puts "[add_slug_to_wildcards] #{self.slug} / #{self.wildcard?}"
(self.wildcards ||= []) << self.slug if self.wildcard? (self.wildcards ||= []) << self.slug if self.wildcard?
end end

View File

@ -74,9 +74,9 @@ module Locomotive
end end
def autosave_for_children? # def autosave_for_children?
@autosave_for_children != false # @autosave_for_children != false
end # end
# Returns the children of this node but with the minimal set of required attributes # Returns the children of this node but with the minimal set of required attributes
# #

View File

@ -12,27 +12,27 @@ module Mongoid#:nodoc:
end end
end end
module Relations #:nodoc: # module Relations #:nodoc:
module AutoSave # module AutoSave
module ClassMethods #:nodoc: # module ClassMethods #:nodoc:
def autosave(metadata) # def autosave(metadata)
if metadata.autosave? # if metadata.autosave?
set_callback :save, :after do |document| # set_callback :save, :after do |document|
relation = document.send(metadata.name) # 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 # return true if document.try(:"autosave_for_#{metadata.name}?") == false # FIXME (Didier L.) add more control on the document side
#
if relation # if relation
(relation.do_or_do_not(:in_memory) || Array.wrap(relation)).each do |doc| # (relation.do_or_do_not(:in_memory) || Array.wrap(relation)).each do |doc|
doc.save # doc.save
end # end
end # end
end # end
end # end
end # end
end # end
end # end
end # end
module Fields #:nodoc: module Fields #:nodoc:
module Internal #:nodoc: module Internal #:nodoc: