Class: Eye::Process::StatesHistory

Inherits:
Utils::Tail show all
Defined in:
lib/eye/process/states_history.rb

Instance Method Summary collapse

Methods inherited from Utils::Tail

#<<, #initialize

Methods inherited from Array

#extract_options!

Constructor Details

This class inherits a constructor from Eye::Utils::Tail

Instance Method Details

#last_reasonObject


21
22
23
# File 'lib/eye/process/states_history.rb', line 21

def last_reason
  last[:reason] rescue nil
end

#last_stateObject


17
18
19
# File 'lib/eye/process/states_history.rb', line 17

def last_state
  last[:state]
end

#last_state_changed_atObject


25
26
27
# File 'lib/eye/process/states_history.rb', line 25

def last_state_changed_at
  Time.at(last[:at])
end

#push(state, reason = nil, tm = Time.now) ⇒ Object


2
3
4
# File 'lib/eye/process/states_history.rb', line 2

def push(state, reason = nil, tm = Time.now)
  super(state: state, at: tm.to_i, reason: reason)
end

#statesObject


6
7
8
# File 'lib/eye/process/states_history.rb', line 6

def states
  self.map{|c| c[:state] }
end

#states_for_period(period, from_time = nil) ⇒ Object


10
11
12
13
14
15
# File 'lib/eye/process/states_history.rb', line 10

def states_for_period(period, from_time = nil)
  tm = Time.now - period
  tm = [tm, from_time].max if from_time
  tm = tm.to_f
  self.select{|s| s[:at] >= tm }.map{|c| c[:state] }
end