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


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

def last_reason
  last[:reason] rescue nil
end

#last_stateObject


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

def last_state
  last[:state]
end

#last_state_changed_atObject


30
31
32
# 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) ⇒ Object


3
4
5
# 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

#statesObject


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

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

#states_for_period(period, from_time = nil, &block) ⇒ Object


11
12
13
14
15
16
17
18
19
20
# 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