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, options = {}) ⇒ 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, options = {}) ⇒ Calculator
Returns a new instance of Calculator.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/bundler/stats/calculator.rb', line 8 def initialize(gemfile_path, lockfile_path, = {}) 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) skiplist = .fetch(:skiplist, []) @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
63 64 65 66 67 68 |
# File 'lib/bundler/stats/calculator.rb', line 63 def gem_stats stats = @gemfile.map do |gem| @tree.summarize(gem.name) end stats.sort_by { |row| row[:total_dependencies] } end |
#github_gems ⇒ Object
53 54 55 56 57 |
# File 'lib/bundler/stats/calculator.rb', line 53 def github_gems @gemfile.select do |dep| dep.source && dep.source..include?("github") end end |
#stats ⇒ Object Also known as: to_h
38 39 40 41 42 |
# File 'lib/bundler/stats/calculator.rb', line 38 def stats { summary: summary, gems: gem_stats } end |
#summarize(target) ⇒ Object
26 27 28 29 30 |
# File 'lib/bundler/stats/calculator.rb', line 26 def summarize(target) @tree.summarize(target).merge({ potential_removals: @remover.potential_removals(target) }) end |
#summary ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/bundler/stats/calculator.rb', line 45 def summary { declared: @gemfile.count, unpinned: unpinned_gems.count, total: @parser.specs.count, github: github_gems.count, } end |
#unpinned_gems ⇒ Object
59 60 61 |
# File 'lib/bundler/stats/calculator.rb', line 59 def unpinned_gems @gemfile.reject { |dep| dep.specific? } end |
#versions(target) ⇒ Object
32 33 34 35 36 |
# File 'lib/bundler/stats/calculator.rb', line 32 def versions(target) @tree.version_requirements(target).merge({ potential_removals: @remover.potential_removals(target) }) end |