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 82 |
# File 'lib/dbus/systemd/manager.rb', line 77 def initialize(bus = Systemd::Helpers.system_bus) @service = bus.service(Systemd::SERVICE) @object = @service.object(NODE) @object.default_iface = INTERFACE @object.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
143 144 145 146 147 |
# File 'lib/dbus/systemd/manager.rb', line 143 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
106 107 108 109 110 |
# File 'lib/dbus/systemd/manager.rb', line 106 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
134 135 136 |
# File 'lib/dbus/systemd/manager.rb', line 134 def job(id) Job.new(id, self) end |
#jobs ⇒ Array
array of jobs from ListJobs mapped to property hashes
125 126 127 |
# File 'lib/dbus/systemd/manager.rb', line 125 def jobs self.ListJobs.first.map { |j| map_job(j) } end |
#map_job(job_array) ⇒ Hash
map job array from ListJobs to property hash
154 155 156 |
# File 'lib/dbus/systemd/manager.rb', line 154 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
117 118 119 |
# File 'lib/dbus/systemd/manager.rb', line 117 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
97 98 99 |
# File 'lib/dbus/systemd/manager.rb', line 97 def unit(name) Unit.new(name, self) end |
#units ⇒ Array
get an array of mapped units/unit properties
88 89 90 |
# File 'lib/dbus/systemd/manager.rb', line 88 def units self.ListUnits.first.map { |u| map_unit(u) } end |