class Eye::Process::StatesHistory

Public Instance Methods

last_reason() click to toggle source
# File lib/eye/process/states_history.rb, line 26
def last_reason
  last[:reason] rescue nil
end
last_state() click to toggle source
# File lib/eye/process/states_history.rb, line 22
def last_state
  last[:state]
end
last_state_changed_at() click to toggle source
# File lib/eye/process/states_history.rb, line 30
def last_state_changed_at
  Time.at(last[:at])
end
push(state, reason = nil, tm = Time.now) click to toggle source
Calls superclass method Eye::Utils::Tail#push
# File lib/eye/process/states_history.rb, line 3
def push(state, reason = nil, tm = Time.now)
  super(state: state, at: tm.to_i, reason: reason)
end
states() click to toggle source
# File lib/eye/process/states_history.rb, line 7
def states
  self.map { |c| c[:state] }
end
states_for_period(period, from_time = nil) { |s| ... } click to toggle source
# File lib/eye/process/states_history.rb, line 11
def states_for_period(period, from_time = nil, &block)
  tm = Time.now - period
  tm = [tm, from_time].max if from_time
  tm = tm.to_f
  if block
    self.each { |s| yield(s) if s[:at] >= tm }
  else
    self.select { |s| s[:at] >= tm }.map { |c| c[:state] }
  end
end