Module: SoftDeleter
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/soft_deleter.rb,
lib/soft_deleter/railtie.rb,
lib/soft_deleter/version.rb
Defined Under Namespace
Classes: Railtie
Constant Summary collapse
- VERSION =
"0.6.2"- @@exclude_dependents =
[]
Instance Method Summary collapse
- #alive? ⇒ Boolean
- #deleter ⇒ Object
- #deleter_type ⇒ Object
- #restore ⇒ Object
- #restore! ⇒ Object
- #soft_delete(deleter = self) ⇒ Object
- #soft_delete!(deleter = self) ⇒ Object
- #soft_deleted? ⇒ Boolean
Instance Method Details
#alive? ⇒ Boolean
76 77 78 |
# File 'lib/soft_deleter.rb', line 76 def alive? self.deleted_at.nil? end |
#deleter ⇒ Object
80 81 82 |
# File 'lib/soft_deleter.rb', line 80 def deleter self.deleter_type&.find_by(id: self.deleter_id) end |
#deleter_type ⇒ Object
68 69 70 |
# File 'lib/soft_deleter.rb', line 68 def deleter_type self[:deleter_type].constantize if self.soft_deleted? end |
#restore ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/soft_deleter.rb', line 58 def restore ActiveRecord::Base.transaction do with_associations(:restore_without_associations) end true rescue ActiveRecord::RecordInvalid false end |
#restore! ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/soft_deleter.rb', line 50 def restore! ActiveRecord::Base.transaction do with_associations(:restore_without_associations!) end true end |
#soft_delete(deleter = self) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/soft_deleter.rb', line 40 def soft_delete(deleter = self) ActiveRecord::Base.transaction do with_associations(:soft_delete_witout_associations, deleter) end true rescue ActiveRecord::RecordInvalid false end |
#soft_delete!(deleter = self) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/soft_deleter.rb', line 32 def soft_delete!(deleter = self) ActiveRecord::Base.transaction do with_associations(:soft_delete_witout_associations!, deleter) end true end |
#soft_deleted? ⇒ Boolean
72 73 74 |
# File 'lib/soft_deleter.rb', line 72 def soft_deleted? self.deleted_at.present? end |