Module: OnDestroy::Model
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/on_destroy/model.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#destroy ⇒ Object
if self.do_not_delete? runs no/empty callback on :destroy, otherwise calls super.
- #destroyed? ⇒ Boolean (also: #deleted?)
-
#do_on_destroy ⇒ Object
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.
-
#really_destroy ⇒ Object
runs delete callback on :destroy.
Instance Method Details
#destroy ⇒ Object
if self.do_not_delete? runs no/empty callback on :destroy, otherwise calls super.
39 40 41 42 43 44 45 46 47 |
# File 'lib/on_destroy/model.rb', line 39 def destroy if self.do_not_delete? # don't destroy run_callbacks(:destroy) {} else # destroy super end end |
#destroyed? ⇒ Boolean Also known as: deleted?
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/on_destroy/model.rb', line 54 def destroyed? if self. is_deleted_if = self.[:is_deleted_if] o_set = self.[:set] o_to = self.[:to] if is_deleted_if.is_a?(Proc) send(o_set) == is_deleted_if.call elsif 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 else super end end |
#do_on_destroy ⇒ Object
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.
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/on_destroy/model.rb', line 27 def do_on_destroy if self. o_set = self.[:set] o_to = self.[:to] if o_set update_attributes! o_set => (o_to.is_a?(Proc) ? o_to.call : o_to) end yield end end |
#really_destroy ⇒ Object
runs delete callback on :destroy
50 51 52 |
# File 'lib/on_destroy/model.rb', line 50 def really_destroy run_callbacks(:destroy) {delete} end |