Class: KuberKit::UI::Simple::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/kuber_kit/ui/simple.rb

Direct Known Subclasses

Api::Task

Instance Method Summary collapse

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

#executeObject



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


16
17
18
# File 'lib/kuber_kit/ui/simple.rb', line 16

def print_finished
  puts "- #{@title.grey}"
end


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

#waitObject



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