Class: Bundler::Stats::Remover
- Inherits:
-
Object
- Object
- Bundler::Stats::Remover
- Defined in:
- lib/bundler/stats/remover.rb
Instance Method Summary collapse
-
#initialize(tree, top_level) ⇒ Remover
constructor
A new instance of Remover.
- #potential_removals(target) ⇒ Object
-
#still_used?(target, deleted: nil) ⇒ Boolean
TODO: woo naive algorithm TODO: circular dependencies would be an issue here TODO: also probably use something like transitive_dependencies to leverage the abilities in tree…
Constructor Details
#initialize(tree, top_level) ⇒ Remover
Returns a new instance of Remover.
4 5 6 7 |
# File 'lib/bundler/stats/remover.rb', line 4 def initialize(tree, top_level) @tree = tree @top_level = top_level end |
Instance Method Details
#potential_removals(target) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/bundler/stats/remover.rb', line 9 def potential_removals(target) candidates = @tree.transitive_dependencies(target) candidates.reject do |candidate| still_used?(candidate.name, deleted: target) end end |
#still_used?(target, deleted: nil) ⇒ Boolean
TODO: woo naive algorithm TODO: circular dependencies would be an issue here TODO: also probably use something like transitive_dependencies to leverage the abilities in tree…
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/bundler/stats/remover.rb', line 20 def still_used?(target, deleted: nil) modified_tree = @tree.tree.clone modified_tree.delete(deleted) deps_to_check = (@top_level - [Gem::Dependency.new(deleted)]) while !deps_to_check.empty? do candidate = deps_to_check.pop.name next if candidate == deleted next if candidate == "bundler" return true if candidate == target deps_to_check += modified_tree[candidate].dependencies end false end |