Class: BoringBuilder::BuildProgress

Inherits:
Object
  • Object
show all
Defined in:
lib/boringbuilder/build_progress.rb

Constant Summary collapse

SPINNER_FRAMES =
%w[         ].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(out: $stdout, enabled: true, animated: false) ⇒ BuildProgress

Returns a new instance of BuildProgress.



11
12
13
14
15
16
# File 'lib/boringbuilder/build_progress.rb', line 11

def initialize(out: $stdout, enabled: true, animated: false)
  @out = out
  @enabled = enabled
  @animated = animated
  @step = 0
end

Class Method Details

.silentObject



7
8
9
# File 'lib/boringbuilder/build_progress.rb', line 7

def self.silent
  @silent ||= new(enabled: false)
end

Instance Method Details

#step(name) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/boringbuilder/build_progress.rb', line 18

def step(name)
  return yield unless @enabled

  number = next_step
  started_at = monotonic_time
  @out.puts "##{number} #{name}"
  @active_spinner = start_spinner(number, started_at)
  result = yield
  stop_active_spinner
  @out.puts "##{number} DONE #{elapsed_since(started_at)}"
  result
rescue StandardError
  stop_active_spinner
  @out.puts "##{number} ERROR #{elapsed_since(started_at)}" if number
  raise
ensure
  stop_active_spinner
end

#write(output = nil) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/boringbuilder/build_progress.rb', line 37

def write(output = nil)
  return unless @enabled

  output = yield if block_given?
  stop_active_spinner
  text = output.to_s
  text.each_line { |line| @out.print "    #{line}" }
  @out.puts unless text.empty? || text.end_with?("\n")
end