Class: KuberKit::UI::Simple::Task
Direct Known Subclasses
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(title, &callback) ⇒ Task
constructor
A new instance of Task.
- #print_finished ⇒ Object
- #print_started ⇒ Object
- #update_title(title) ⇒ Object
- #wait ⇒ Object
Constructor Details
#initialize(title, &callback) ⇒ Task
Returns a new instance of Task.
7 8 9 10 |
# File 'lib/kuber_kit/ui/simple.rb', line 7 def initialize(title, &callback) @title = title @callback = callback end |
Instance Method Details
#execute ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/kuber_kit/ui/simple.rb', line 20 def execute if @thread raise "Already started execution of task '#{title}'" end @thread = Thread.new do Thread.current.abort_on_exception = true Thread.current.report_on_exception = false print_started @callback.call(self) print_finished end end |
#print_finished ⇒ Object
16 17 18 |
# File 'lib/kuber_kit/ui/simple.rb', line 16 def print_finished puts "- #{@title.grey}" end |
#print_started ⇒ Object
12 13 14 |
# File 'lib/kuber_kit/ui/simple.rb', line 12 def print_started puts "- #{@title}" end |
#update_title(title) ⇒ Object
41 42 43 |
# File 'lib/kuber_kit/ui/simple.rb', line 41 def update_title(title) @title = title end |
#wait ⇒ Object
34 35 36 37 38 39 |
# File 'lib/kuber_kit/ui/simple.rb', line 34 def wait if !@thread raise "Task '#{title}' not started" end @thread.join end |