class Rake::Funnel::Support::Timing::Report

Constants

HEADER_WIDTH
SPACE

Public Class Methods

new(stats, opts = {}) click to toggle source
# File lib/rake/funnel/support/timing/report.rb, line 38
def initialize(stats, opts = {})
  @stats = stats
  @opts = opts
end

Public Instance Methods

columns() click to toggle source
# File lib/rake/funnel/support/timing/report.rb, line 49
def columns
  @columns ||= begin [
    Column.new(stats: @stats, header: 'Target', accessor: ->(timing) { timing[:task].name }),
    Column.new(stats: @stats, header: 'Duration', accessor: ->(timing) { format(timing[:time]) })
  ] end
end
render() click to toggle source
# File lib/rake/funnel/support/timing/report.rb, line 43
def render
  header
  rows
  footer
end

Private Instance Methods

format(seconds) click to toggle source
# File lib/rake/funnel/support/timing/report.rb, line 80
def format(seconds)
  Time.at(seconds).utc.strftime('%H:%M:%S')
end
header() click to toggle source
# File lib/rake/funnel/support/timing/report.rb, line 58
def header # rubocop:disable Metrics/AbcSize
  $stdout.print '-' * HEADER_WIDTH + "\n"
  $stdout.print "Build time report\n"
  $stdout.print '-' * HEADER_WIDTH + "\n"

  $stdout.print columns.map(&:format_header).join(' ' * SPACE) + "\n"
  $stdout.print columns.map { |c| c.format_header.gsub(/./, '-') }.join(' ' * SPACE) + "\n"
end
rows() click to toggle source
# File lib/rake/funnel/support/timing/report.rb, line 67
def rows
  @stats.each do |timing|
    $stdout.print columns.map { |c| c.format_value(timing) }.join(' ' * SPACE) + "\n"
  end
end
status_message() click to toggle source
# File lib/rake/funnel/support/timing/report.rb, line 84
def status_message # rubocop:disable Metrics/AbcSize
  status = @opts[:failed] ? 'Failed' : 'OK'
  status = 'Status'.ljust(columns[0].width) + ' ' * SPACE + status

  if @opts[:failed]
    $stderr.print(status.bold.red + "\n")
  else
    $stdout.print(status.bold.green + "\n")
  end
end