Module: FatJam::ActsAsRevisable::Deletable

Defined in:
lib/acts_as_revisable/acts/deletable.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
8
9
# File 'lib/acts_as_revisable/acts/deletable.rb', line 4

def self.included(base)        
  base.instance_eval do
    alias_method_chain :destroy, :revisable
    define_callbacks :before_destroy_with_revisable, :after_destroy_with_revisable
  end
end

Instance Method Details

#destroy_with_revisableObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/acts_as_revisable/acts/deletable.rb', line 11

def destroy_with_revisable
  now = Time.now
  
  prev = self.revisions.first
  self.revisable_deleted_at = now
  self.revisable_is_current = false
          
  self.revisable_current_at = if prev
    prev.update_attribute(:revisable_revised_at, now)
    prev.revisable_revised_at + 1.second
  else
    self.created_at
  end
  
  self.revisable_revised_at = self.revisable_deleted_at
  run_callbacks(:before_destroy_with_revisable)
  self.save(:without_revision => true)
  run_callbacks(:after_destroy_with_revisable)
end