Class: RubyRich::ProgressManager::Handle

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_rich/progress_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(manager, id:, owner:, message:) ⇒ Handle

Returns a new instance of Handle.



12
13
14
15
16
17
18
# File 'lib/ruby_rich/progress_manager.rb', line 12

def initialize(manager, id:, owner:, message:)
  @manager = manager
  @id = id
  @owner = owner
  @message = message
  @state = :running
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/ruby_rich/progress_manager.rb', line 10

def id
  @id
end

#messageObject (readonly)

Returns the value of attribute message.



10
11
12
# File 'lib/ruby_rich/progress_manager.rb', line 10

def message
  @message
end

#ownerObject (readonly)

Returns the value of attribute owner.



10
11
12
# File 'lib/ruby_rich/progress_manager.rb', line 10

def owner
  @owner
end

#stateObject (readonly)

Returns the value of attribute state.



10
11
12
# File 'lib/ruby_rich/progress_manager.rb', line 10

def state
  @state
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/ruby_rich/progress_manager.rb', line 39

def active?
  @state == :running
end

#cancel(message = "Cancelled") ⇒ Object



35
36
37
# File 'lib/ruby_rich/progress_manager.rb', line 35

def cancel(message = "Cancelled")
  close(:cancelled, message)
end

#fail(message = "Failed") ⇒ Object



31
32
33
# File 'lib/ruby_rich/progress_manager.rb', line 31

def fail(message = "Failed")
  close(:error, message)
end

#finish(message = "Done") ⇒ Object



27
28
29
# File 'lib/ruby_rich/progress_manager.rb', line 27

def finish(message = "Done")
  close(:done, message)
end

#update(message) ⇒ Object



20
21
22
23
24
25
# File 'lib/ruby_rich/progress_manager.rb', line 20

def update(message)
  return false unless active?

  @message = message.to_s
  @manager.update(@id, @owner, @message)
end