Class: SystemdMon::State

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/systemd_mon/state.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(active, sub, loaded, unit_file) ⇒ 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)
  timestamp   = Time.now
  @active     = StateValue.new("active", active, timestamp, %w(active), %w(inactive))
  @sub        = StateValue.new("status", sub, timestamp)
  @loaded     = StateValue.new("loaded", loaded, timestamp, %w(loaded))
  @unit_file  = StateValue.new("file", unit_file, timestamp, %w(enabled), %w(disabled))
  @all_states = [@active, @sub, @loaded, @unit_file]
end

Instance Attribute Details

#activeObject (readonly)

Returns the value of attribute active.



7
8
9
# File 'lib/systemd_mon/state.rb', line 7

def active
  @active
end

#all_statesObject (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

#loadedObject (readonly)

Returns the value of attribute loaded.



7
8
9
# File 'lib/systemd_mon/state.rb', line 7

def loaded
  @loaded
end

#subObject (readonly)

Returns the value of attribute sub.



7
8
9
# File 'lib/systemd_mon/state.rb', line 7

def sub
  @sub
end

#unit_fileObject (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

#eachObject



18
19
20
21
22
# File 'lib/systemd_mon/state.rb', line 18

def each
  @all_states.each do |state|
    yield state
  end
end

#fail?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/systemd_mon/state.rb', line 28

def fail?
  any?(&:fail?)
end

#ok?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/systemd_mon/state.rb', line 24

def ok?
  all?(&:ok?)
end