Module: BigRecord::Deletion

Defined in:
lib/big_record/deletion.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary

Instance Method Summary

Class Method Details

+ (Object) included(base)

:nodoc:



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/big_record/deletion.rb', line 3

def self.included(base) #:nodoc:
  base.alias_method_chain :destroy_without_callbacks, :flag_deleted
  base.extend ClassMethods

  base.class_eval do
    class << self
      alias_method_chain :find_one, :flag_deleted
      alias_method_chain :find_every, :flag_deleted
    end
  end

end

Instance Method Details

- (Object) destroy_without_callbacks_with_flag_deleted

Flag the record as "deleted" if it responds to "deleted", else destroy it



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/big_record/deletion.rb', line 17

def destroy_without_callbacks_with_flag_deleted 
  if self.respond_to?(:deleted)
    # mark as deleted
    self.deleted = true

    # set the timestamp
    if record_timestamps
      t = self.class.default_timezone == :utc ? Time.now.utc : Time.now
      self.send(:updated_at=, t) if respond_to?(:updated_at)
      self.send(:updated_on=, t) if respond_to?(:updated_on)
    end

    self.update_without_callbacks
  else
    destroy_without_callbacks_without_flag_deleted
  end
end