Class: SystemdMon::State
- Inherits:
-
Object
- Object
- SystemdMon::State
- Includes:
- Enumerable
- Defined in:
- lib/systemd_mon/state.rb
Instance Attribute Summary collapse
-
#active ⇒ Object
readonly
Returns the value of attribute active.
-
#all_states ⇒ Object
readonly
Returns the value of attribute all_states.
-
#loaded ⇒ Object
readonly
Returns the value of attribute loaded.
-
#sub ⇒ Object
readonly
Returns the value of attribute sub.
-
#unit_file ⇒ Object
readonly
Returns the value of attribute unit_file.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #active_states(type) ⇒ Object
- #each ⇒ Object
- #fail? ⇒ Boolean
- #file_states(type) ⇒ Object
-
#initialize(active, sub, loaded, unit_file, type = nil) ⇒ State
constructor
A new instance of State.
- #ok? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(active, sub, loaded, unit_file, type = nil) ⇒ State
Returns a new instance of State.
9 10 11 12 13 14 15 16 |
# File 'lib/systemd_mon/state.rb', line 9 def initialize(active, sub, loaded, unit_file, type=nil) = Time.now @active = StateValue.new("active", active, , *active_states(type)) @sub = StateValue.new("status", sub, ) @loaded = StateValue.new("loaded", loaded, , %w(loaded)) @unit_file = StateValue.new("file", unit_file, , *file_states(type)) @all_states = [@active, @sub, @loaded, @unit_file] end |
Instance Attribute Details
#active ⇒ Object (readonly)
Returns the value of attribute active.
7 8 9 |
# File 'lib/systemd_mon/state.rb', line 7 def active @active end |
#all_states ⇒ Object (readonly)
Returns the value of attribute all_states.
7 8 9 |
# File 'lib/systemd_mon/state.rb', line 7 def all_states @all_states end |
#loaded ⇒ Object (readonly)
Returns the value of attribute loaded.
7 8 9 |
# File 'lib/systemd_mon/state.rb', line 7 def loaded @loaded end |
#sub ⇒ Object (readonly)
Returns the value of attribute sub.
7 8 9 |
# File 'lib/systemd_mon/state.rb', line 7 def sub @sub end |
#unit_file ⇒ Object (readonly)
Returns the value of attribute unit_file.
7 8 9 |
# File 'lib/systemd_mon/state.rb', line 7 def unit_file @unit_file end |
Instance Method Details
#==(other) ⇒ Object
54 55 56 |
# File 'lib/systemd_mon/state.rb', line 54 def ==(other) @all_states == other.all_states end |
#active_states(type) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/systemd_mon/state.rb', line 18 def active_states(type) case type when 'oneshot' [%w(inactive), %w(failed)] else [%w(active), %w(inactive failed)] end end |
#each ⇒ Object
36 37 38 39 40 |
# File 'lib/systemd_mon/state.rb', line 36 def each @all_states.each do |state| yield state end end |
#fail? ⇒ Boolean
46 47 48 |
# File 'lib/systemd_mon/state.rb', line 46 def fail? any?(&:fail?) end |
#file_states(type) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/systemd_mon/state.rb', line 27 def file_states(type) case type when 'oneshot' [[], []] else [%w(enabled linked-runtime static), %w(disabled)] end end |
#ok? ⇒ Boolean
42 43 44 |
# File 'lib/systemd_mon/state.rb', line 42 def ok? all?(&:ok?) end |
#to_s ⇒ Object
50 51 52 |
# File 'lib/systemd_mon/state.rb', line 50 def to_s @all_states.join(', ') end |