Class: DBus::Systemd::Manager
- Inherits:
-
Object
- Object
- DBus::Systemd::Manager
- Defined in:
- lib/dbus/systemd/manager.rb
Constant Summary collapse
- NODE =
systemd manager object dbus node path
'/org/freedesktop/systemd1'.freeze
- INTERFACE =
systemd manager dbus interface
'org.freedesktop.systemd1.Manager'.freeze
- UNIT_INDICES =
index map of unit array returned by ListUnits
{ 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 }.freeze
- JOB_INDICES =
index map of job array returned by ListJobs
{ id: 0, unit: 1, type: 2, state: 3, object_path: 4, unit_object_path: 5 }.freeze
Instance Attribute Summary collapse
- #service ⇒ DBus::Service readonly private
Attributes included from DBus::Systemd::Mixin::MethodMissing
Instance Method Summary collapse
-
#get_job_by_object_path(path) ⇒ DBus::Systemd::Job
get job by dbus node path.
-
#get_unit_by_object_path(path) ⇒ DBus::Systemd::Unit
get unit object by dbus node path.
-
#initialize(bus = Systemd::Helpers.system_bus) ⇒ Manager
constructor
Create a systemd manager dbus proxy object.
-
#job(id) ⇒ DBus::Systemd::Job
get job by id.
-
#jobs ⇒ Array
array of jobs from ListJobs mapped to property hashes.
-
#map_job(job_array) ⇒ Hash
map job array from ListJobs to property hash.
-
#map_unit(unit_array) ⇒ Hash
map unit array from ListUnits to property hash.
-
#unit(name) ⇒ DBus::Systemd::Unit
get a unit dbus proxy object by name.
-
#units ⇒ Array
get an array of mapped units/unit properties.
Methods included from DBus::Systemd::Mixin::Properties
Methods included from DBus::Systemd::Mixin::MethodMissing
#method_missing, #respond_to_missing?
Constructor Details
#initialize(bus = Systemd::Helpers.system_bus) ⇒ Manager
Create a systemd manager dbus proxy object
77 78 79 80 81 |
# File 'lib/dbus/systemd/manager.rb', line 77 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
#service ⇒ DBus::Service (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
71 72 73 |
# File 'lib/dbus/systemd/manager.rb', line 71 def service @service end |
Instance Method Details
#get_job_by_object_path(path) ⇒ DBus::Systemd::Job
get job by dbus node path
142 143 144 145 146 |
# File 'lib/dbus/systemd/manager.rb', line 142 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) ⇒ DBus::Systemd::Unit
get unit object by dbus node path
105 106 107 108 109 |
# File 'lib/dbus/systemd/manager.rb', line 105 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) ⇒ DBus::Systemd::Job
get job by id
133 134 135 |
# File 'lib/dbus/systemd/manager.rb', line 133 def job(id) Job.new(id, self) end |
#jobs ⇒ Array
array of jobs from ListJobs mapped to property hashes
124 125 126 |
# File 'lib/dbus/systemd/manager.rb', line 124 def jobs self.ListJobs.first.map { |j| map_job(j) } end |
#map_job(job_array) ⇒ Hash
map job array from ListJobs to property hash
153 154 155 |
# File 'lib/dbus/systemd/manager.rb', line 153 def map_job(job_array) Helpers.map_array(job_array, JOB_INDICES) end |
#map_unit(unit_array) ⇒ Hash
map unit array from ListUnits to property hash
116 117 118 |
# File 'lib/dbus/systemd/manager.rb', line 116 def map_unit(unit_array) Helpers.map_array(unit_array, UNIT_INDICES) end |
#unit(name) ⇒ DBus::Systemd::Unit
get a unit dbus proxy object by name
96 97 98 |
# File 'lib/dbus/systemd/manager.rb', line 96 def unit(name) Unit.new(name, self) end |
#units ⇒ Array
get an array of mapped units/unit properties
87 88 89 |
# File 'lib/dbus/systemd/manager.rb', line 87 def units self.ListUnits.first.map { |u| map_unit(u) } end |