Class: Yard::Lint::Formatters::Progress

Inherits:
Object
  • Object
show all
Defined in:
lib/yard/lint/formatters/progress.rb

Overview

Simple progress formatter that shows which validator is running Similar to RuboCop’s progress display

Instance Method Summary collapse

Constructor Details

#initialize(output = $stdout) ⇒ Progress

Initialize progress formatter

Parameters:

  • output (IO) (defaults to: $stdout)

    output stream (default: $stdout)



12
13
14
15
16
# File 'lib/yard/lint/formatters/progress.rb', line 12

def initialize(output = $stdout)
  @output = output
  @total = 0
  @current = 0
end

Instance Method Details

#finishObject

Finish progress display



43
44
45
46
# File 'lib/yard/lint/formatters/progress.rb', line 43

def finish
  @output.print "\r\e[K" # Clear the progress line
  @output.flush
end

#start(total) ⇒ Object

Start progress display

Parameters:

  • total (Integer)

    total number of validators



20
21
22
23
24
# File 'lib/yard/lint/formatters/progress.rb', line 20

def start(total)
  @total = total
  @current = 0
  @output.print "Inspecting with #{total} validators\n"
end

#update(current, validator_name) ⇒ Object

Update progress with current validator

Parameters:

  • current (Integer)

    current validator number

  • validator_name (String)

    name of the validator



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/yard/lint/formatters/progress.rb', line 29

def update(current, validator_name)
  @current = current
  # Clear line and show progress
  @output.print "\r\e[K" # Clear line
  @output.print format(
    '[%<current>d/%<total>d] %<name>s',
    current: current,
    total: @total,
    name: validator_name
  )
  @output.flush
end