Class: BlastRadius::ImpactCalculator
- Inherits:
-
Object
- Object
- BlastRadius::ImpactCalculator
- Defined in:
- lib/blast_radius/impact_calculator.rb
Instance Method Summary collapse
-
#calculate(record, options = {}) ⇒ Hash
Calculate the impact of deleting a specific record.
-
#dry_run(record, options = {}) ⇒ Hash
Perform a dry run to see what would be deleted.
-
#initialize(configuration = nil) ⇒ ImpactCalculator
constructor
A new instance of ImpactCalculator.
Constructor Details
#initialize(configuration = nil) ⇒ ImpactCalculator
Returns a new instance of ImpactCalculator.
5 6 7 |
# File 'lib/blast_radius/impact_calculator.rb', line 5 def initialize(configuration = nil) @configuration = configuration || BlastRadius.configuration end |
Instance Method Details
#calculate(record, options = {}) ⇒ Hash
Calculate the impact of deleting a specific record
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/blast_radius/impact_calculator.rb', line 17 def calculate(record, = {}) tree_builder = DependencyTree.new(@configuration) tree = tree_builder.build(record.class, ) impact = Hash.new(0) # Start with root node's children tree.children.each do |child| calculate_node_impact(child, record, impact) end impact end |
#dry_run(record, options = {}) ⇒ Hash
Perform a dry run to see what would be deleted
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/blast_radius/impact_calculator.rb', line 34 def dry_run(record, = {}) tree_builder = DependencyTree.new(@configuration) tree = tree_builder.build(record.class, ) impact = {} # Start with root node's children tree.children.each do |child| calculate_detailed_impact(child, record, impact) end impact end |