Class: DBus::Systemd::Manager

Inherits:
Object
  • Object
show all
Includes:
DBus::Systemd::Mixin::MethodMissing, DBus::Systemd::Mixin::Properties
Defined in:
lib/dbus/systemd/manager.rb

Constant Summary collapse

NODE =
'/org/freedesktop/systemd1'
INTERFACE =
'org.freedesktop.systemd1.Manager'
UNIT_INDICES =
{
  name: 0,
  description: 1,
  load_state: 2,
  active_state: 3,
  sub_state: 4,
  following: 5,
  object_path: 6,
  job_id: 7,
  job_type: 8,
  job_object_path: 9
}
JOB_INDICES =
{
  id: 0,
  unit: 1,
  type: 2,
  state: 3,
  object_path: 4,
  unit_object_path: 5
}

Instance Attribute Summary collapse

Attributes included from DBus::Systemd::Mixin::MethodMissing

#object

Instance Method Summary collapse

Methods included from DBus::Systemd::Mixin::Properties

#properties

Methods included from DBus::Systemd::Mixin::MethodMissing

#method_missing, #respond_to_missing?

Constructor Details

#initialize(bus = Systemd::Helpers.system_bus) ⇒ Manager

Returns a new instance of Manager.



45
46
47
48
49
# File 'lib/dbus/systemd/manager.rb', line 45

def initialize(bus = Systemd::Helpers.system_bus)
  @service = bus.service(Systemd::INTERFACE)
  @object = @service.object(NODE)
                    .tap(&:introspect)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class DBus::Systemd::Mixin::MethodMissing

Instance Attribute Details

#serviceObject (readonly)

Returns the value of attribute service.



43
44
45
# File 'lib/dbus/systemd/manager.rb', line 43

def service
  @service
end

Instance Method Details

#get_job_by_object_path(path) ⇒ Object



77
78
79
80
81
# File 'lib/dbus/systemd/manager.rb', line 77

def get_job_by_object_path(path)
  obj = @service.object(path)
                .tap(&:introspect)
  Job.new(obj.Get(Job::INTERFACE, 'Id').first, self)
end

#get_unit_by_object_path(path) ⇒ Object



59
60
61
62
63
# File 'lib/dbus/systemd/manager.rb', line 59

def get_unit_by_object_path(path)
  obj = @service.object(path)
                .tap(&:introspect)
  Unit.new(obj.Get(Unit::INTERFACE, 'Id').first, self)
end

#job(id) ⇒ Object



73
74
75
# File 'lib/dbus/systemd/manager.rb', line 73

def job(id)
  Job.new(id, self)
end

#jobsObject



69
70
71
# File 'lib/dbus/systemd/manager.rb', line 69

def jobs
  self.ListJobs.first.map { |j| map_job(j) }
end

#map_job(job_array) ⇒ Object



83
84
85
# File 'lib/dbus/systemd/manager.rb', line 83

def map_job(job_array)
  Helpers.map_array(job_array, JOB_INDICES)
end

#map_unit(unit_array) ⇒ Object



65
66
67
# File 'lib/dbus/systemd/manager.rb', line 65

def map_unit(unit_array)
  Helpers.map_array(unit_array, UNIT_INDICES)
end

#unit(name) ⇒ Object



55
56
57
# File 'lib/dbus/systemd/manager.rb', line 55

def unit(name)
  Unit.new(name, self)
end

#unitsObject



51
52
53
# File 'lib/dbus/systemd/manager.rb', line 51

def units
  self.ListUnits.first.map { |u| map_unit(u) }
end