Class: Dex::UI::Spinner::SpinGroup::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/dex/ui/spinner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, &block) ⇒ Task

Returns a new instance of Task.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/dex/ui/spinner.rb', line 31

def initialize(title, &block)
  @title = title
  @thread = Thread.new do
    cap = Dex::UI::StdoutRouter::Capture.new(with_frame_inset: false, &block)
    begin
      cap.run
    ensure
      @stdout = cap.stdout
      @stderr = cap.stderr
    end
  end

  @done      = false
  @exception = nil
  @success   = false
end

Instance Attribute Details

#exceptionObject (readonly)

Returns the value of attribute exception.



29
30
31
# File 'lib/dex/ui/spinner.rb', line 29

def exception
  @exception
end

#stderrObject (readonly)

Returns the value of attribute stderr.



29
30
31
# File 'lib/dex/ui/spinner.rb', line 29

def stderr
  @stderr
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



29
30
31
# File 'lib/dex/ui/spinner.rb', line 29

def stdout
  @stdout
end

#successObject (readonly)

Returns the value of attribute success.



29
30
31
# File 'lib/dex/ui/spinner.rb', line 29

def success
  @success
end

#titleObject (readonly)

Returns the value of attribute title.



29
30
31
# File 'lib/dex/ui/spinner.rb', line 29

def title
  @title
end

Instance Method Details

#checkObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/dex/ui/spinner.rb', line 48

def check
  return true if @done
  return false if @thread.alive?

  @done = true
  begin
    status = @thread.join.status
    @success = (status == false)
  rescue => exc
    @exception = exc
    @success = false
  end

  @done
end

#render(index, force = true) ⇒ Object



64
65
66
67
# File 'lib/dex/ui/spinner.rb', line 64

def render(index, force = true)
  return full_render(index) if force
  partial_render(index)
end