class GemFresh::Calculator

Constants

FRAMEWORK_MULTIPLIER
LOCAL_MULTIPLIER
MINIMAL_MULTIPLIER

Point multipliers based on how central the gem is to the application code.

POINTS_FOR_MAJOR

If a gem is behind by a major version, it's worth more points than a minor version.

POINTS_FOR_MINOR
POINTS_FOR_PATCH
SYSTEM_MULTIPLIER

Public Class Methods

new() click to toggle source
# File lib/gem_fresh/calculator.rb, line 16
def initialize
  @freshness_scores = {}
end

Public Instance Methods

all_scores() click to toggle source
# File lib/gem_fresh/calculator.rb, line 29
def all_scores
  @freshness_scores
end
calculate!() click to toggle source
# File lib/gem_fresh/calculator.rb, line 20
def calculate!
  @gem_freshness_info = GemFresh::Outdated.new.gem_info
  calculate_freshness_scores_for_each_gem
end
total_score() click to toggle source
# File lib/gem_fresh/calculator.rb, line 25
def total_score
  @freshness_scores.values.sum.round(1)
end

Private Instance Methods

calculate_for_gems(gems, multiplier) click to toggle source
# File lib/gem_fresh/calculator.rb, line 42
def calculate_for_gems(gems, multiplier)
  gems.each do |gem_name|
    @freshness_scores[gem_name] =
     (calculate_freshness_score_for(gem_name) * multiplier).round(1)
  end
end
calculate_freshness_score_for(gem_name) click to toggle source
# File lib/gem_fresh/calculator.rb, line 49
def calculate_freshness_score_for(gem_name)
  info = @gem_freshness_info[gem_name]
  return 0 if info.nil?  # no outdated info means it's fresh
  major_diff = (info[:available_version].major - info[:current_version].major)
  minor_diff = (info[:available_version].minor - info[:current_version].minor)
  patch_diff = (info[:available_version].patch - info[:current_version].patch)
  score = 0
  if major_diff > 0
    score += major_diff * POINTS_FOR_MAJOR
  elsif minor_diff > 0
    score += minor_diff * POINTS_FOR_MINOR
  elsif patch_diff > 0
    score += patch_diff * POINTS_FOR_PATCH
  end
  score
end
calculate_freshness_scores_for_each_gem() click to toggle source
# File lib/gem_fresh/calculator.rb, line 35
def calculate_freshness_scores_for_each_gem
  calculate_for_gems(['rails'], FRAMEWORK_MULTIPLIER)
  calculate_for_gems(Config.config.system_wide_gems, SYSTEM_MULTIPLIER)
  calculate_for_gems(Config.config.local_gems, LOCAL_MULTIPLIER)
  calculate_for_gems(Config.config.minimal_gems, MINIMAL_MULTIPLIER)
end