class Central::Devtools::Rake::Flay

Flay metric runner

Constants

ABOVE_THRESHOLD
BELOW_THRESHOLD
TOTAL_MISMATCH

Public Instance Methods

verify() click to toggle source

Verify code specified by `files` does not violate flay expectations

@raise [SystemExit] if a violation is found @return [undefined] otherwise

rubocop:disable MethodLength

@api private

# File lib/central/devtools/rake/flay.rb, line 24
def verify
  # Run flay first to ensure the max mass matches the threshold
  Central::Devtools.notify_metric_violation(
    BELOW_THRESHOLD % largest_mass
  ) if below_threshold?

  Central::Devtools.notify_metric_violation(
    TOTAL_MISMATCH % [total_mass, total_score]
  ) if total_mismatch?

  # Run flay a second time with the threshold set
  return unless above_threshold?

  restricted_flay_scale.flay_report
  Central::Devtools.notify_metric_violation(
    ABOVE_THRESHOLD % [restricted_mass_size, threshold]
  )
end

Private Instance Methods

above_threshold?() click to toggle source

Is there mass duplication which exceeds specified `threshold`

@return [Boolean] @api private

# File lib/central/devtools/rake/flay.rb, line 57
def above_threshold?
  restricted_mass_size.nonzero?
end
below_threshold?() click to toggle source

Is the specified `threshold` greater than the largest flay mass

@return [Boolean] @api private

# File lib/central/devtools/rake/flay.rb, line 65
def below_threshold?
  threshold > largest_mass
end
files() click to toggle source

List of files flay will analyze

@return [Set<Pathname>] @api private

# File lib/central/devtools/rake/flay.rb, line 49
def files
  Central::Devtools::Flay::FileList.call(lib_dirs, excludes)
end
flay_masses() click to toggle source

All flay masses found in `files`

@return [Array<Rational>] @api private

# File lib/central/devtools/rake/flay.rb, line 114
def flay_masses
  Central::Devtools::Flay::Scale.call(minimum_mass: 0, files: files)
end
largest_mass() click to toggle source

Largest flay mass found

@return [Integer] @api private

# File lib/central/devtools/rake/flay.rb, line 97
def largest_mass
  flay_masses.max.to_i
end
restricted_flay_scale() click to toggle source

Flay scale which only measures mass above `threshold`

@return [Flay::Scale] @api private

# File lib/central/devtools/rake/flay.rb, line 105
def restricted_flay_scale
  Central::Devtools::Flay::Scale.new(minimum_mass: threshold.succ, files: files)
end
restricted_mass_size() click to toggle source

Size of mass measured by `Flay::Scale` and filtered by `threshold`

@return [Integer] @api private

# File lib/central/devtools/rake/flay.rb, line 81
def restricted_mass_size
  restricted_flay_scale.measure.size
end
total_mass() click to toggle source

Sum of all flay mass

@return [Integer] @api private

# File lib/central/devtools/rake/flay.rb, line 89
def total_mass
  flay_masses.reduce(:+).to_i
end
total_mismatch?() click to toggle source

Is the expected mass total different from the actual mass total

@return [Boolean] @api private

# File lib/central/devtools/rake/flay.rb, line 73
def total_mismatch?
  !total_mass.equal?(total_score)
end