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, 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)
  timestamp   = Time.now
  @active     = StateValue.new("active", active, timestamp, *active_states(type))
  @sub        = StateValue.new("status", sub, timestamp)
  @loaded     = StateValue.new("loaded", loaded, timestamp, %w(loaded))
  @unit_file  = StateValue.new("file", unit_file, timestamp, *file_states(type))
  @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

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

#eachObject



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

Returns:

  • (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

Returns:

  • (Boolean)


42
43
44
# File 'lib/systemd_mon/state.rb', line 42

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

#to_sObject



50
51
52
# File 'lib/systemd_mon/state.rb', line 50

def to_s
  @all_states.join(', ')
end