Class: ActiveRecord::Base
- Inherits:
-
Object
- Object
- ActiveRecord::Base
- Defined in:
- lib/paranoia.rb
Class Method Summary collapse
Instance Method Summary collapse
- #paranoid? ⇒ Boolean
-
#persisted? ⇒ Boolean
Override the persisted method to allow for the paranoia gem.
Class Method Details
.acts_as_paranoid(options = {}) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/paranoia.rb', line 105 def self.acts_as_paranoid(={}) alias :ar_destroy :destroy alias :destroy! :ar_destroy alias :delete! :delete include Paranoia class_attribute :paranoia_column self.paranoia_column = [:column] || :deleted_at default_scope { where(self.quoted_table_name + ".#{paranoia_column} IS NULL") } 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 |
.paranoid? ⇒ Boolean
123 124 125 |
# File 'lib/paranoia.rb', line 123 def self.paranoid? false end |
Instance Method Details
#paranoid? ⇒ Boolean
127 128 129 |
# File 'lib/paranoia.rb', line 127 def paranoid? self.class.paranoid? end |
#persisted? ⇒ Boolean
Override the persisted method to allow for the paranoia gem. If a paranoid record is selected, then we only want to check if it’s a new record, not if it is “destroyed”.
134 135 136 |
# File 'lib/paranoia.rb', line 134 def persisted? paranoid? ? !new_record? : super end |