Class: DInstaller::ServiceStatusRecorder

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeServiceStatusRecorder

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_servicesArray<String>

Name of services with busy status

Returns:



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

Parameters:



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

Parameters:

  • see ServiceStatus



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