Sha256: f342ff6385b76f12cf42e22d689cdd9d3bd38cc97ce76e713a1623e60c1b190b
Contents?: true
Size: 1.05 KB
Versions: 3
Compression:
Stored size: 1.05 KB
Contents
module SoftDeletion class Dependency attr_reader :record, :association_name def initialize(record, association_name) @record = record @association_name = association_name end def soft_delete! return unless can_soft_delete? if nullify? nullify_dependencies else dependencies.each(&:soft_delete!) end end def soft_undelete! return unless can_soft_delete? klass.with_deleted do dependencies.each(&:soft_undelete!) end end protected def nullify? association.options[:dependent] == :nullify end def nullify_dependencies dependencies.each do |dependency| dependency.update_attribute(association.primary_key_name, nil) end end def can_soft_delete? respond_to? :soft_delete! end def klass association.klass end def association record.class.reflect_on_association(association_name.to_sym) end def dependencies Array.wrap(record.send(association_name)) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
soft_deletion-0.1.5 | lib/soft_deletion/dependency.rb |
soft_deletion-0.1.4 | lib/soft_deletion/dependency.rb |
soft_deletion-0.1.3 | lib/soft_deletion/dependency.rb |