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
- #progress ⇒ Progress? readonly
Instance Method Summary collapse
-
#on_progress_change(&block) ⇒ Object
Registers an on_change callback to be added to the progress.
-
#on_progress_finish(&block) ⇒ Object
Registers an on_finish callback to be added to the progress.
-
#start_progress(total_steps) ⇒ Object
Creates a new progress.
Instance Attribute Details
#progress ⇒ Progress? (readonly)
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
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
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
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 |