Class: SoftDeletion::Dependency
- Inherits:
-
Object
- Object
- SoftDeletion::Dependency
- Defined in:
- lib/soft_deletion/dependency.rb
Instance Attribute Summary collapse
-
#association_name ⇒ Object
readonly
Returns the value of attribute association_name.
-
#record ⇒ Object
readonly
Returns the value of attribute record.
Instance Method Summary collapse
-
#initialize(record, association_name) ⇒ Dependency
constructor
A new instance of Dependency.
- #soft_delete! ⇒ Object
- #soft_undelete!(limit) ⇒ Object
Constructor Details
#initialize(record, association_name) ⇒ Dependency
Returns a new instance of Dependency.
5 6 7 8 |
# File 'lib/soft_deletion/dependency.rb', line 5 def initialize(record, association_name) @record = record @association_name = association_name end |
Instance Attribute Details
#association_name ⇒ Object (readonly)
Returns the value of attribute association_name.
3 4 5 |
# File 'lib/soft_deletion/dependency.rb', line 3 def association_name @association_name end |
#record ⇒ Object (readonly)
Returns the value of attribute record.
3 4 5 |
# File 'lib/soft_deletion/dependency.rb', line 3 def record @record end |
Instance Method Details
#soft_delete! ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/soft_deletion/dependency.rb', line 10 def soft_delete! case association.[:dependent] when :nullify nullify_dependencies when :delete_all dependency.update_all(:deleted_at => Time.now) else dependencies.each(&:soft_delete!) end end |
#soft_undelete!(limit) ⇒ Object
21 22 23 24 25 |
# File 'lib/soft_deletion/dependency.rb', line 21 def soft_undelete!(limit) klass.with_deleted do dependencies.reject { |m| m.deleted_at < limit }.each(&:soft_undelete!) end end |