Module: SoftDestroyable::InstanceMethods

Defined in:
lib/soft_destroyable.rb

Instance Method Summary collapse

Instance Method Details

#after_soft_destroyObject

override



135
136
137
# File 'lib/soft_destroyable.rb', line 135

def after_soft_destroy
  # empty
end

#before_destroy!Object

override



140
141
142
# File 'lib/soft_destroyable.rb', line 140

def before_destroy!
  # empty
end

#before_soft_destroyObject

override



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

def before_soft_destroy
  # empty
end

#destroyObject

overrides the normal ActiveRecord::Transactions#destroy. can be recovered with revive



95
96
97
98
99
100
# File 'lib/soft_destroyable.rb', line 95

def destroy
  before_soft_destroy
  result = soft_destroy
  after_soft_destroy
  result
end

#destroy!Object

not a recoverable operation



103
104
105
106
107
108
109
# File 'lib/soft_destroyable.rb', line 103

def destroy!
  transaction do
    before_destroy!
    cascade_destroy!
    delete
  end
end

#restrict_dependenciesObject



125
126
127
# File 'lib/soft_destroyable.rb', line 125

def restrict_dependencies
  self.class.restrict_dependencies
end

#reviveObject

un-does the effect of destroy. Does not undo nullify on dependents



112
113
114
115
116
117
118
119
# File 'lib/soft_destroyable.rb', line 112

def revive
  transaction do
    cascade_revive
    update_hash = {:deleted_at => nil, :deleted => false}
    update_hash[:revive_with_parent] = true if respond_to?(:revive_with_parent)
    update_attributes(update_hash)
  end
end

#soft_dependenciesObject



121
122
123
# File 'lib/soft_destroyable.rb', line 121

def soft_dependencies
  self.class.soft_dependencies
end