Module: DInstaller::WithProgress

Included in:
DBus::Clients::Manager, DBus::Clients::Software, Manager, Software
Defined in:
lib/dinstaller/with_progress.rb

Overview

Mixin that allows to start a progress and configure callbacks

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#progressProgress? (readonly)

Returns:



28
29
30
# File 'lib/dinstaller/with_progress.rb', line 28

def progress
  @progress
end

Instance Method Details

#on_progress_change(&block) ⇒ Object

Registers an on_change callback to be added to the progress

Parameters:

  • block (Proc)


50
51
52
53
# File 'lib/dinstaller/with_progress.rb', line 50

def on_progress_change(&block)
  @on_progress_change_callbacks ||= []
  @on_progress_change_callbacks << block
end

#on_progress_finish(&block) ⇒ Object

Registers an on_finish callback to be added to the progress

Parameters:

  • block (Proc)


58
59
60
61
# File 'lib/dinstaller/with_progress.rb', line 58

def on_progress_finish(&block)
  @on_progress_finish_callbacks ||= []
  @on_progress_finish_callbacks << block
end

#start_progress(total_steps) ⇒ Object

Creates a new progress

Parameters:

  • total_steps (Integer)

    total number of the steps for the progress.

Raises:

  • (RuntimeError)

    if there is an unfinished progress.



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/dinstaller/with_progress.rb', line 35

def start_progress(total_steps)
  raise "There already is an unfinished progress" if progress && !progress.finished?

  on_change_callbacks = @on_progress_change_callbacks || []
  on_finish_callbacks = @on_progress_finish_callbacks || []

  @progress = Progress.new(total_steps).tap do |progress|
    progress.on_change { on_change_callbacks.each(&:call) }
    progress.on_finish { on_finish_callbacks.each(&:call) }
  end
end