Class: NestedAttributeDestruction::Monitor

Inherits:
Object
  • Object
show all
Defined in:
lib/nested_attribute_destruction/monitor.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMonitor

Returns a new instance of Monitor.



5
6
7
8
# File 'lib/nested_attribute_destruction/monitor.rb', line 5

def initialize
  @attributes_marked_for_destruction = Set.new
  @attributes_destroyed_during_last_save = Set.new
end

Class Method Details

.define_hooks(klass) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/nested_attribute_destruction/monitor.rb', line 11

def define_hooks(klass)
  return if hooks_defined?(klass)

  define_callbacks(klass)
  redefine_reload(klass)

  hooks_defined!(klass)
end

.define_predicate(klass, assoc_name) ⇒ Object



20
21
22
23
24
# File 'lib/nested_attribute_destruction/monitor.rb', line 20

def define_predicate(klass, assoc_name)
  klass.define_method("#{assoc_name}_destroyed_during_save?") do
    @nested_attribute_destruction_monitor.send(:destroyed_during_save?, assoc_name.to_sym)
  end
end