Class: Bundler::Stats::Calculator
- Inherits:
-
Object
- Object
- Bundler::Stats::Calculator
- Defined in:
- lib/bundler/stats/calculator.rb
Instance Attribute Summary collapse
-
#gemfile ⇒ Object
readonly
Returns the value of attribute gemfile.
-
#parser ⇒ Object
readonly
Returns the value of attribute parser.
-
#remover ⇒ Object
readonly
Returns the value of attribute remover.
-
#tree ⇒ Object
readonly
Returns the value of attribute tree.
Instance Method Summary collapse
- #gem_stats ⇒ Object
- #github_gems ⇒ Object
-
#initialize(gemfile_path, lockfile_path, skiplist = nil) ⇒ Calculator
constructor
A new instance of Calculator.
- #stats ⇒ Object (also: #to_h)
- #summarize(target) ⇒ Object
- #summary ⇒ Object
- #unpinned_gems ⇒ Object
- #versions(target) ⇒ Object
Constructor Details
#initialize(gemfile_path, lockfile_path, skiplist = nil) ⇒ Calculator
Returns a new instance of Calculator.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/bundler/stats/calculator.rb', line 8 def initialize(gemfile_path, lockfile_path, skiplist = nil) raise ArgumentError unless File.readable?(lockfile_path) raise ArgumentError unless File.readable?(gemfile_path) @gemfile = Bundler::Dsl.new @gemfile.eval_gemfile(gemfile_path) @gemfile = @gemfile.dependencies raise ArgumentError, "Couldn't parse Gemfile at #{gemfile_path.realdirpath}" unless @gemfile lock_contents = File.read(lockfile_path) @parser = Bundler::LockfileParser.new(lock_contents) @tree = Bundler::Stats::Tree.new(@parser, skiplist: skiplist) @remover = Bundler::Stats::Remover.new(@tree, @gemfile) end |
Instance Attribute Details
#gemfile ⇒ Object (readonly)
Returns the value of attribute gemfile.
6 7 8 |
# File 'lib/bundler/stats/calculator.rb', line 6 def gemfile @gemfile end |
#parser ⇒ Object (readonly)
Returns the value of attribute parser.
6 7 8 |
# File 'lib/bundler/stats/calculator.rb', line 6 def parser @parser end |
#remover ⇒ Object (readonly)
Returns the value of attribute remover.
6 7 8 |
# File 'lib/bundler/stats/calculator.rb', line 6 def remover @remover end |
#tree ⇒ Object (readonly)
Returns the value of attribute tree.
6 7 8 |
# File 'lib/bundler/stats/calculator.rb', line 6 def tree @tree end |
Instance Method Details
#gem_stats ⇒ Object
61 62 63 64 65 66 |
# File 'lib/bundler/stats/calculator.rb', line 61 def gem_stats stats = @gemfile.map do |gem| @tree.summarize(gem.name) end stats.sort_by { |row| [row[:total_dependencies] * -1, row[:name]] } end |
#github_gems ⇒ Object
51 52 53 54 55 |
# File 'lib/bundler/stats/calculator.rb', line 51 def github_gems @gemfile.select do |dep| dep.source && dep.source..include?("github") end end |
#stats ⇒ Object Also known as: to_h
36 37 38 39 40 |
# File 'lib/bundler/stats/calculator.rb', line 36 def stats { summary: summary, gems: gem_stats } end |
#summarize(target) ⇒ Object
24 25 26 27 28 |
# File 'lib/bundler/stats/calculator.rb', line 24 def summarize(target) @tree.summarize(target).merge({ potential_removals: @remover.potential_removals(target) }) end |
#summary ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/bundler/stats/calculator.rb', line 43 def summary { declared: @gemfile.count, unpinned: unpinned_gems.count, total: @parser.specs.count, github: github_gems.count, } end |
#unpinned_gems ⇒ Object
57 58 59 |
# File 'lib/bundler/stats/calculator.rb', line 57 def unpinned_gems @gemfile.reject { |dep| dep.specific? } end |
#versions(target) ⇒ Object
30 31 32 33 34 |
# File 'lib/bundler/stats/calculator.rb', line 30 def versions(target) @tree.version_requirements(target).merge({ potential_removals: @remover.potential_removals(target) }) end |