Module: ConcernsOnRails::SoftDeletable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/concerns_on_rails/soft_deletable.rb
Instance Method Summary collapse
- #after_restore ⇒ Object
- #after_soft_delete ⇒ Object
- #before_restore ⇒ Object
-
#before_soft_delete ⇒ Object
Soft delete hooks.
- #deleted? ⇒ Boolean (also: #is_soft_deleted?, #soft_deleted?)
- #is_really_deleted? ⇒ Boolean
-
#really_delete! ⇒ Object
bypasses AR callbacks and validations — use when you want a true hard delete.
- #restore! ⇒ Object
- #soft_delete! ⇒ Object
Instance Method Details
#after_restore ⇒ Object
49 |
# File 'lib/concerns_on_rails/soft_deletable.rb', line 49 def after_restore; end |
#after_soft_delete ⇒ Object
47 |
# File 'lib/concerns_on_rails/soft_deletable.rb', line 47 def after_soft_delete; end |
#before_restore ⇒ Object
48 |
# File 'lib/concerns_on_rails/soft_deletable.rb', line 48 def before_restore; end |
#before_soft_delete ⇒ Object
Soft delete hooks
46 |
# File 'lib/concerns_on_rails/soft_deletable.rb', line 46 def before_soft_delete; end |
#deleted? ⇒ Boolean Also known as: is_soft_deleted?, soft_deleted?
81 82 83 |
# File 'lib/concerns_on_rails/soft_deletable.rb', line 81 def deleted? self[self.class.soft_delete_field].present? end |
#is_really_deleted? ⇒ Boolean
90 91 92 |
# File 'lib/concerns_on_rails/soft_deletable.rb', line 90 def is_really_deleted? !self.class.unscoped.exists?(id) end |
#really_delete! ⇒ Object
bypasses AR callbacks and validations — use when you want a true hard delete
76 77 78 79 |
# File 'lib/concerns_on_rails/soft_deletable.rb', line 76 def really_delete! self.class.unscoped.where(self.class.primary_key => id).delete_all freeze end |
#restore! ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/concerns_on_rails/soft_deletable.rb', line 63 def restore! return true unless deleted? before_restore result = if self.class.soft_delete_touch update(self.class.soft_delete_field => nil) else update_column(self.class.soft_delete_field, nil) end after_restore if result result end |
#soft_delete! ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/concerns_on_rails/soft_deletable.rb', line 51 def soft_delete! return true if deleted? before_soft_delete result = if self.class.soft_delete_touch update(self.class.soft_delete_field => Time.zone.now) else update_column(self.class.soft_delete_field, Time.zone.now) end after_soft_delete if result result end |