Class: ActiveRecord::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/paranoia.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.acts_as_paranoid(options = {}) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/paranoia.rb', line 115

def self.acts_as_paranoid(options={})
  alias :really_destroy! :destroy
  alias :destroy! :destroy
  alias :delete! :delete
  include Paranoia
  class_attribute :paranoia_column

  self.paranoia_column = options[:column] || :deleted_at
  default_scope { where(paranoia_column => nil) }

  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.



135
136
137
138
139
140
141
142
# File 'lib/paranoia.rb', line 135

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

.paranoid?Boolean



144
# File 'lib/paranoia.rb', line 144

def self.paranoid? ; false ; end

Instance Method Details

#paranoid?Boolean



145
# File 'lib/paranoia.rb', line 145

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”.



150
151
152
# File 'lib/paranoia.rb', line 150

def persisted?
  paranoid? ? !new_record? : super
end