Module: Caboose::Acts::Paranoid::InstanceMethods
- Defined in:
- lib/caboose/acts/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
Class Method Details
.included(base) ⇒ Object
:nodoc:
79 80 81 |
# File 'lib/caboose/acts/paranoid.rb', line 79 def self.included(base) # :nodoc: base.extend ClassMethods end |
Instance Method Details
#deleted? ⇒ Boolean
157 158 159 |
# File 'lib/caboose/acts/paranoid.rb', line 157 def deleted? !!read_attribute(:deleted_at) end |
#destroy! ⇒ Object
153 154 155 |
# File 'lib/caboose/acts/paranoid.rb', line 153 def destroy! transaction { destroy_with_callbacks! } end |
#destroy_with_callbacks! ⇒ Object
146 147 148 149 150 151 |
# File 'lib/caboose/acts/paranoid.rb', line 146 def destroy_with_callbacks! return false if callback(:before_destroy) == false result = destroy_without_callbacks! callback(:after_destroy) result end |
#destroy_without_callbacks ⇒ Object
139 140 141 142 143 144 |
# File 'lib/caboose/acts/paranoid.rb', line 139 def destroy_without_callbacks unless new_record? self.class.update_all self.class.send(:sanitize_sql, ["#{self.class.deleted_attribute} = ?", self.class.send(:current_time)]), ["#{self.class.primary_key} = ?", id] end freeze end |
#recover! ⇒ Object
161 162 163 164 |
# File 'lib/caboose/acts/paranoid.rb', line 161 def recover! self.deleted_at = nil save! end |