Class: ForemanMaintain::Reporter::CLIReporter::Spinner
- Inherits:
-
Object
- Object
- ForemanMaintain::Reporter::CLIReporter::Spinner
- Defined in:
- lib/foreman_maintain/reporter/cli_reporter.rb
Overview
Simple spinner able to keep updating current line
Instance Method Summary collapse
- #activate ⇒ Object
- #active? ⇒ Boolean
- #deactivate ⇒ Object
-
#initialize(reporter, interval = 0.1) ⇒ Spinner
constructor
A new instance of Spinner.
- #update(line) ⇒ Object
Constructor Details
#initialize(reporter, interval = 0.1) ⇒ Spinner
Returns a new instance of Spinner.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/foreman_maintain/reporter/cli_reporter.rb', line 10 def initialize(reporter, interval = 0.1) @reporter = reporter @mutex = Mutex.new @active = false @interval = interval @spinner_index = 0 @spinner_chars = %w[| / - \\] @current_line = '' @puts_needed = false start_spinner end |
Instance Method Details
#activate ⇒ Object
33 34 35 36 |
# File 'lib/foreman_maintain/reporter/cli_reporter.rb', line 33 def activate @mutex.synchronize { @active = true } spin end |
#active? ⇒ Boolean
29 30 31 |
# File 'lib/foreman_maintain/reporter/cli_reporter.rb', line 29 def active? @mutex.synchronize { @active } end |
#deactivate ⇒ Object
38 39 40 41 42 43 |
# File 'lib/foreman_maintain/reporter/cli_reporter.rb', line 38 def deactivate return unless active? @mutex.synchronize do @active = false end end |
#update(line) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/foreman_maintain/reporter/cli_reporter.rb', line 22 def update(line) @mutex.synchronize do @current_line = line print_current_line end end |