class 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

@api private

# File lib/devtools/rake/flay.rb, line 22
def verify
  # Run flay first to ensure the max mass matches the threshold
  below_threshold_message if below_threshold?

  total_mismatch_message if total_mismatch?

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

  restricted_flay_scale.flay_report
  above_threshold_message
end

Private Instance Methods

above_threshold?() click to toggle source

Is there mass duplication which exceeds specified `threshold`

@return [Boolean]

@api private

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

Above threshold message

@return [String]

@api private

# File lib/devtools/rake/flay.rb, line 78
def above_threshold_message
  format_values = { mass: restricted_mass_size, threshold: threshold }
  Devtools.notify_metric_violation(
    format(ABOVE_THRESHOLD, format_values)
  )
end
below_threshold?() click to toggle source

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

@return [Boolean]

@api private

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

Below threshold message

@return [String]

@api private

# File lib/devtools/rake/flay.rb, line 90
def below_threshold_message
  Devtools.notify_metric_violation(
    format(BELOW_THRESHOLD, mass: largest_mass)
  )
end
files() click to toggle source

List of files flay will analyze

@return [Set<Pathname>]

@api private

# File lib/devtools/rake/flay.rb, line 42
def files
  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/devtools/rake/flay.rb, line 149
def flay_masses
  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/devtools/rake/flay.rb, line 130
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/devtools/rake/flay.rb, line 139
def restricted_flay_scale
  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/devtools/rake/flay.rb, line 112
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/devtools/rake/flay.rb, line 121
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/devtools/rake/flay.rb, line 69
def total_mismatch?
  !total_mass.equal?(total_score)
end
total_mismatch_message() click to toggle source

Total mismatch message

@return [String]

@api private

# File lib/devtools/rake/flay.rb, line 101
def total_mismatch_message
  Devtools.notify_metric_violation(
    format(TOTAL_MISMATCH, mass: total_mass, expected: total_score)
  )
end