Module: ParanoidFu::Paranoid::InstanceMethods
- Defined in:
- lib/paranoid_fu/paranoid.rb
Overview
:nodoc:
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(base) ⇒ Object
:nodoc:.
Instance Method Summary collapse
- #deleted? ⇒ Boolean
- #destroy! ⇒ Object
- #destroy_with_callbacks! ⇒ Object
- #destroy_without_callbacks ⇒ Object
- #recover! ⇒ Object
- #recover_with_associations!(*associations) ⇒ Object
Class Method Details
.included(base) ⇒ Object
:nodoc:
74 75 76 |
# File 'lib/paranoid_fu/paranoid.rb', line 74 def self.included(base) # :nodoc: base.extend ClassMethods end |
Instance Method Details
#deleted? ⇒ Boolean
115 116 117 |
# File 'lib/paranoid_fu/paranoid.rb', line 115 def deleted? !!read_attribute(:deleted_at) end |
#destroy! ⇒ Object
111 112 113 |
# File 'lib/paranoid_fu/paranoid.rb', line 111 def destroy! transaction { destroy_with_callbacks! } end |
#destroy_with_callbacks! ⇒ Object
104 105 106 107 108 109 |
# File 'lib/paranoid_fu/paranoid.rb', line 104 def destroy_with_callbacks! return false if callback(:before_destroy) == false result = destroy_without_callbacks! callback(:after_destroy) result end |
#destroy_without_callbacks ⇒ Object
97 98 99 100 101 102 |
# File 'lib/paranoid_fu/paranoid.rb', line 97 def destroy_without_callbacks unless new_record? self.class.update_all self.class.send(:sanitize_sql, ["#{self.class.deleted_attribute} = ?", (self.deleted_at = self.class.send(:current_time))]), ["#{self.class.primary_key} = ?", id] end freeze end |
#recover! ⇒ Object
119 120 121 122 |
# File 'lib/paranoid_fu/paranoid.rb', line 119 def recover! self.deleted_at = nil save! end |
#recover_with_associations!(*associations) ⇒ Object
124 125 126 127 128 129 130 131 |
# File 'lib/paranoid_fu/paranoid.rb', line 124 def recover_with_associations!(*associations) self.recover! associations.to_a.each do |assoc| self.send(assoc).all.each do |a| a.recover! if a.class.paranoid? end end end |