Class: ActiveRecord::Base
- Inherits:
-
Object
- Object
- ActiveRecord::Base
- Defined in:
- lib/paranoia.rb
Class Method Summary collapse
- .acts_as_paranoid(options = {}) ⇒ Object
-
.I_AM_THE_DESTROYER! ⇒ Object
Please do not use this method in production.
- .paranoia_scope ⇒ Object
- .paranoid? ⇒ Boolean
Instance Method Summary collapse
Class Method Details
.acts_as_paranoid(options = {}) ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/paranoia.rb', line 152 def self.acts_as_paranoid(={}) alias :really_destroyed? :destroyed? alias :really_delete :delete alias :destroy_without_paranoia :destroy def really_destroy! dependent_reflections = self.class.reflections.select do |name, reflection| reflection.[:dependent] == :destroy end if dependent_reflections.any? dependent_reflections.each do |name, reflection| association_data = self.send(name) # has_one association can return nil # .paranoid? will work for both instances and classes if association_data && association_data.paranoid? if reflection.collection? association_data.with_deleted.each(&:really_destroy!) else association_data.really_destroy! end end end end write_attribute(paranoia_column, current_time_from_proper_timezone) destroy_without_paranoia end include Paranoia class_attribute :paranoia_column, :paranoia_sentinel_value self.paranoia_column = ([:column] || :deleted_at).to_s self.paranoia_sentinel_value = .fetch(:sentinel_value) { Paranoia.default_sentinel_value } def self.paranoia_scope where(table_name => { paranoia_column => paranoia_sentinel_value }) end default_scope { paranoia_scope } before_restore { self.class.notify_observers(:before_restore, self) if self.class.respond_to?(:notify_observers) } after_restore { self.class.notify_observers(:after_restore, self) if self.class.respond_to?(:notify_observers) } end |
.I_AM_THE_DESTROYER! ⇒ Object
Please do not use this method in production. Pretty please.
199 200 201 202 203 204 205 206 |
# File 'lib/paranoia.rb', line 199 def self.I_AM_THE_DESTROYER! # TODO: actually implement spelling error fixes puts %Q{ Sharon: "There should be a method called I_AM_THE_DESTROYER!" Ryan: "What should this method do?" Sharon: "It should fix all the spelling errors on the page!" } end |
.paranoia_scope ⇒ Object
184 185 186 |
# File 'lib/paranoia.rb', line 184 def self.paranoia_scope where(table_name => { paranoia_column => paranoia_sentinel_value }) end |
.paranoid? ⇒ Boolean
208 |
# File 'lib/paranoia.rb', line 208 def self.paranoid? ; false ; end |
Instance Method Details
#paranoid? ⇒ Boolean
209 |
# File 'lib/paranoia.rb', line 209 def paranoid? ; self.class.paranoid? ; end |
#really_destroy! ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/paranoia.rb', line 157 def really_destroy! dependent_reflections = self.class.reflections.select do |name, reflection| reflection.[:dependent] == :destroy end if dependent_reflections.any? dependent_reflections.each do |name, reflection| association_data = self.send(name) # has_one association can return nil # .paranoid? will work for both instances and classes if association_data && association_data.paranoid? if reflection.collection? association_data.with_deleted.each(&:really_destroy!) else association_data.really_destroy! end end end end write_attribute(paranoia_column, current_time_from_proper_timezone) destroy_without_paranoia end |