lib/rake/funnel/support/timing/report.rb in rake-funnel-0.18.0 vs lib/rake/funnel/support/timing/report.rb in rake-funnel-0.19.0
- old
+ new
@@ -6,18 +6,18 @@
module Timing
class Report
class Column
attr_reader :header
- def initialize(stats: [], header: '', accessor: -> (_) { '' })
+ def initialize(stats: [], header: '', accessor: ->(_) { '' })
@stats = stats
@header = header
@accessor = accessor
end
def width
- longest_value = @stats.map { |s| @accessor.call(s) }.max_by { |m| m.length } || ''
+ longest_value = @stats.map { |s| @accessor.call(s) }.max_by(&:length) || ''
width = longest_value.length
width = @header.length if width < @header.length
width
end
@@ -43,43 +43,44 @@
rows
footer
end
def columns
- @columns ||= ([
- Column.new(stats: @stats, header: 'Target', accessor: -> (timing) { timing[:task].name }),
- Column.new(stats: @stats, header: 'Duration', accessor: -> (timing) { format(timing[:time]) })
- ])
+ @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
private
- def header
+
+ def header # rubocop:disable Metrics/AbcSize
puts '-' * HEADER_WIDTH
puts 'Build time report'
puts '-' * HEADER_WIDTH
- puts columns.map { |c| c.format_header }.join(' ' * SPACE)
+ puts columns.map(&:format_header).join(' ' * SPACE)
puts columns.map { |c| c.format_header.gsub(/./, '-') }.join(' ' * SPACE)
end
def rows
@stats.each do |timing|
puts columns.map { |c| c.format_value(timing) }.join(' ' * SPACE)
end
end
- def footer
+ def footer # rubocop:disable Metrics/AbcSize
puts '-' * HEADER_WIDTH
puts 'Total'.ljust(columns[0].width) + ' ' * SPACE + format(Time.now - @stats.started_at)
status_message
puts '-' * HEADER_WIDTH
end
def format(seconds)
Time.at(seconds).utc.strftime('%H:%M:%S')
end
- def status_message
+ def status_message # rubocop:disable Metrics/AbcSize
status = @opts[:failed] ? 'Failed' : 'OK'
status = 'Status'.ljust(columns[0].width) + ' ' * SPACE + status
if @opts[:failed]
$stderr.puts status.bold.red