Module: Familia::Features::Relationships::Cascading::InstanceMethods
- Defined in:
- lib/familia/features/relationships/cascading.rb
Overview
Instance methods for cascade operations
Instance Method Summary collapse
-
#cascade_impact ⇒ Object
Check if destroying this object would trigger cascades.
-
#execute_cascade_operations ⇒ Object
Execute cascade operations during destroy.
-
#remove_from_all_collections ⇒ Object
Remove this object from all collections without cascading.
Instance Method Details
#cascade_impact ⇒ Object
Check if destroying this object would trigger cascades
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/familia/features/relationships/cascading.rb', line 108 def cascade_impact strategies = self.class.cascade_strategies impact = { removals: 0, cascades: 0, affected_collections: [], cascade_targets: [] } strategies.each do |key, strategy_info| case strategy_info[:strategy] when :remove impact[:removals] += 1 impact[:affected_collections] << key when :cascade impact[:cascades] += 1 impact[:affected_collections] << key # Estimate cascade targets (this is expensive, use carefully) targets = estimate_cascade_targets(strategy_info) impact[:cascade_targets].concat(targets) end end impact end |
#execute_cascade_operations ⇒ Object
Execute cascade operations during destroy
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/familia/features/relationships/cascading.rb', line 75 def execute_cascade_operations strategies = self.class.cascade_strategies # Group operations by strategy for efficient execution remove_operations = [] cascade_operations = [] strategies.each_value do |strategy_info| case strategy_info[:strategy] when :remove remove_operations << strategy_info when :cascade cascade_operations << strategy_info when :ignore # Do nothing end end # Execute remove operations first (cleanup this object's presence) execute_remove_operations(remove_operations) if remove_operations.any? # Then execute cascade operations (may trigger other destroys) execute_cascade_operations_recursive(cascade_operations) if cascade_operations.any? end |
#remove_from_all_collections ⇒ Object
Remove this object from all collections without cascading
101 102 103 104 105 |
# File 'lib/familia/features/relationships/cascading.rb', line 101 def remove_from_all_collections strategies = self.class.cascade_strategies remove_operations = strategies.values.reject { |s| s[:strategy] == :ignore } execute_remove_operations(remove_operations) end |