Class: SoftDeletion::Dependency

Inherits:
Object
  • Object
show all
Defined in:
lib/soft_deletion/dependency.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_nameObject (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

#recordObject (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
# File 'lib/soft_deletion/dependency.rb', line 10

def soft_delete!
  return unless can_soft_delete?

  if nullify?
    nullify_dependencies
  else
    dependencies.each(&:soft_delete!)
  end
end

#soft_undelete!Object



20
21
22
23
24
25
26
# File 'lib/soft_deletion/dependency.rb', line 20

def soft_undelete!
  return unless can_soft_delete?

  klass.with_deleted do
    dependencies.each(&:soft_undelete!)
  end
end