Class: DInstaller::ServiceStatusRecorder
- Inherits:
-
Object
- Object
- DInstaller::ServiceStatusRecorder
- Defined in:
- lib/dinstaller/service_status_recorder.rb
Overview
Allows to record the status of services and to register callbacks to be called when a service status changes its value
Instance Method Summary collapse
-
#busy_services ⇒ Array<String>
Name of services with busy status.
-
#initialize ⇒ ServiceStatusRecorder
constructor
A new instance of ServiceStatusRecorder.
-
#on_service_status_change(&block) ⇒ Object
Registers callbacks to be called when saving a new status.
-
#save(service_name, status) ⇒ Object
Saves the status of the given service and runs the callbacks if the status has changed.
Constructor Details
#initialize ⇒ ServiceStatusRecorder
Returns a new instance of ServiceStatusRecorder.
28 29 30 31 |
# File 'lib/dinstaller/service_status_recorder.rb', line 28 def initialize @statuses = {} @on_service_status_change_callbacks = [] end |
Instance Method Details
#busy_services ⇒ Array<String>
Name of services with busy status
47 48 49 |
# File 'lib/dinstaller/service_status_recorder.rb', line 47 def busy_services @statuses.select { |_service, status| status == DBus::ServiceStatus::BUSY }.keys end |
#on_service_status_change(&block) ⇒ Object
Registers callbacks to be called when saving a new status
54 55 56 |
# File 'lib/dinstaller/service_status_recorder.rb', line 54 def on_service_status_change(&block) @on_service_status_change_callbacks << block end |
#save(service_name, status) ⇒ Object
Saves the status of the given service and runs the callbacks if the status has changed
37 38 39 40 41 42 |
# File 'lib/dinstaller/service_status_recorder.rb', line 37 def save(service_name, status) return if @statuses[service_name] == status @statuses[service_name] = status @on_service_status_change_callbacks.each(&:call) end |