Module: Immortal::InstanceMethods

Defined in:
lib/immortal.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



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

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



119
120
121
# File 'lib/immortal.rb', line 119

def destroy!
  mortal_destroy
end

#destroy_without_callbacksObject



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

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

#immortal_destroyObject



113
114
115
116
117
# File 'lib/immortal.rb', line 113

def immortal_destroy
  run_callbacks :destroy do
    destroy_without_callbacks
  end
end

#recover!Object



129
130
131
132
# File 'lib/immortal.rb', line 129

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