Class: Resquire::Analyzer
- Inherits:
-
Object
- Object
- Resquire::Analyzer
- Defined in:
- lib/resquire/analyzer.rb
Instance Attribute Summary collapse
-
#gems ⇒ Object
readonly
gem dependencies, as an array.
Instance Method Summary collapse
-
#add_gem(gem) ⇒ Object
We can add one gem at a time as a string.
-
#add_gems(gems = []) ⇒ Object
We can add gems specified from an array.
-
#initialize(args = {}) ⇒ Analyzer
constructor
When we create a new Analyzer, we can specifiy the gems we want to work with, but it must be passed in as an array in the args hash.
-
#optimized_gems ⇒ Object
Once we have figured out the redundant gems, we can easily check out our optimized gem list which we can now use.
-
#permutations(gems = @gems) ⇒ Object
We can check the given permutations that we will need to cycle through to find gems that are redundant.
-
#redundant_gems(args = {}) ⇒ Object
We can find the redundant gems from the the analyzer has to work with, iterating over the possible permutations and returning an array of redundant gems.
Constructor Details
#initialize(args = {}) ⇒ Analyzer
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/resquire/analyzer.rb', line 15 def initialize(args = {}) @gems = [] @redundant_gems = [] if args[:gems] if args[:gems].is_a? Array add_gems(args[:gems]) else raise Resquire::ResquireError.new('Dependencies must be initialized as an array!') end end true end |
Instance Attribute Details
#gems ⇒ Object (readonly)
gem dependencies, as an array
5 6 7 |
# File 'lib/resquire/analyzer.rb', line 5 def gems @gems end |
Instance Method Details
#add_gem(gem) ⇒ Object
48 49 50 51 52 |
# File 'lib/resquire/analyzer.rb', line 48 def add_gem(gem) @gems << gem @gems = @gems.uniq true end |
#add_gems(gems = []) ⇒ Object
35 36 37 38 |
# File 'lib/resquire/analyzer.rb', line 35 def add_gems(gems = []) gems.uniq.each { |gem| @gems << gem } true end |
#optimized_gems ⇒ Object
99 100 101 102 |
# File 'lib/resquire/analyzer.rb', line 99 def optimized_gems optimized_gems = @gems.reject { |gem| @redundant_gems.include? gem } optimized_gems.empty? ? false : optimized_gems.uniq.sort end |
#permutations(gems = @gems) ⇒ Object
63 64 65 |
# File 'lib/resquire/analyzer.rb', line 63 def permutations(gems = @gems) (1..gems.count).reduce(:*) || 1 end |
#redundant_gems(args = {}) ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'lib/resquire/analyzer.rb', line 77 def redundant_gems(args = {}) find_redundant_gems_with_gem(args) @count = 0 @permutation_count = permutations @progress_bar = args[:progress_bar] || true gems = args[:gems] || @gems redundant = args[:redundant_gems] || @redundant_gems find_redundant_gems(args).empty? ? false : @redundant_gems end |