module OnDestroy::Model
Public Instance Methods
destroy()
click to toggle source
if self.do_not_delete? runs no/empty callback on :destroy, otherwise calls super.
Calls superclass method
# File lib/on_destroy/model.rb, line 37 def destroy if self.do_not_delete? # don't destroy run_callbacks(:destroy) {} else # destroy super end end
destroyed?()
click to toggle source
Calls superclass method
# File lib/on_destroy/model.rb, line 52 def destroyed? if self.on_destroy_options is_deleted_if = self.on_destroy_options[:is_deleted_if] o_set = self.on_destroy_options[:set] o_to = self.on_destroy_options[:to] if is_deleted_if.is_a?(Proc) send(o_set) == is_deleted_if.call elsif !(o_set.nil?) if o_to.is_a?(Proc) # assume that a :to defined as a Proc is going to evaluate to a non-nil to indicate the model is null send(o_set) != nil else send(o_set) == o_to end end else super end end
Also aliased as: deleted?
do_on_destroy() { || ... }
click to toggle source
if self.set then will use update_attributes! to set the self.set attribute to self.to or self.to.call if it is a Proc.
# File lib/on_destroy/model.rb, line 27 def do_on_destroy if self.on_destroy_options o_set = self.on_destroy_options[:set] o_to = self.on_destroy_options[:to] update_attributes! o_set => (o_to.is_a?(Proc) ? o_to.call : o_to) unless o_set.nil? yield end end
really_destroy()
click to toggle source
runs delete callback on :destroy
# File lib/on_destroy/model.rb, line 48 def really_destroy run_callbacks(:destroy) {delete} end