Module: ActsAsParanoid::InstanceMethods
- Defined in:
- lib/rails3_acts_as_paranoid.rb
Instance Method Summary collapse
- #deleted? ⇒ Boolean (also: #destroyed?)
- #destroy ⇒ Object
- #destroy! ⇒ Object
- #paranoid_value ⇒ Object
- #recover(options = {}) ⇒ Object
- #recover_dependent_associations(window, options) ⇒ Object
Instance Method Details
#deleted? ⇒ Boolean Also known as: destroyed?
154 155 156 |
# File 'lib/rails3_acts_as_paranoid.rb', line 154 def deleted? !paranoid_value.nil? end |
#destroy ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/rails3_acts_as_paranoid.rb', line 105 def destroy with_transaction_returning_status do run_callbacks :destroy do if paranoid_value == nil self.class.delete_all(:id => self.id) else self.class.delete_all!(:id => self.id) end self.paranoid_value = self.class.delete_now_value end end end |
#destroy! ⇒ Object
95 96 97 98 99 100 101 102 103 |
# File 'lib/rails3_acts_as_paranoid.rb', line 95 def destroy! with_transaction_returning_status do run_callbacks :destroy do self.class.delete_all!(:id => self) self.paranoid_value = self.class.delete_now_value freeze end end end |
#paranoid_value ⇒ Object
91 92 93 |
# File 'lib/rails3_acts_as_paranoid.rb', line 91 def paranoid_value self.send(self.class.paranoid_column) end |
#recover(options = {}) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/rails3_acts_as_paranoid.rb', line 118 def recover( = {}) = { :recursive => self.class.paranoid_configuration[:recover_dependent_associations], :recovery_window => self.class.paranoid_configuration[:dependent_recovery_window] }.merge() self.class.transaction do recover_dependent_associations([:recovery_window], ) if [:recursive] self.update_attributes(self.class.paranoid_column.to_sym => nil) end end |
#recover_dependent_associations(window, options) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/rails3_acts_as_paranoid.rb', line 131 def recover_dependent_associations(window, ) self.class.dependent_associations.each do |association| if association.collection? && self.send(association.name).paranoid? self.send(association.name).unscoped do self.send(association.name).deleted_around(paranoid_value, window).each do |object| object.recover() if object.respond_to?(:recover) end end elsif association.macro == :has_one && association.klass.paranoid? association.klass.unscoped do object = association.klass.deleted_around(paranoid_value, window).send('find_by_'+association.primary_key_name, self.id) object.recover() if object && object.respond_to?(:recover) end elsif association.klass.paranoid? association.klass.unscoped do id = self.send(association.primary_key_name) object = association.klass.deleted_around(paranoid_value, window).find_by_id(id) object.recover() if object && object.respond_to?(:recover) end end end end |