Module: Immortal::InstanceMethods

Defined in:
lib/immortal.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



98
99
100
101
102
103
104
# File 'lib/immortal.rb', line 98

def self.included(base)
  base.class_eval do
    default_scope where(arel_table[:deleted].eq(nil).or(arel_table[:deleted].eq(false))) if arel_table[:deleted]
    alias :mortal_destroy :destroy
    alias :destroy :immortal_destroy
  end
end

Instance Method Details

#destroy!Object



112
113
114
# File 'lib/immortal.rb', line 112

def destroy!
  mortal_destroy
end

#destroy_without_callbacksObject



116
117
118
119
120
# File 'lib/immortal.rb', line 116

def destroy_without_callbacks
  self.class.unscoped.update_all({ :deleted => true }, "id = #{self.id}")
  reload
  freeze
end

#immortal_destroyObject



106
107
108
109
110
# File 'lib/immortal.rb', line 106

def immortal_destroy
  run_callbacks :destroy do
    destroy_without_callbacks
  end
end

#recover!Object



122
123
124
125
# File 'lib/immortal.rb', line 122

def recover!
  self.class.unscoped.update_all({ :deleted => false }, "id = #{self.id}")
  reload
end