Class: Eye::Process::StatesHistory
Instance Method Summary
collapse
Methods inherited from Utils::Tail
#<<, #initialize
Methods inherited from Array
#extract_options!
Instance Method Details
#last_reason ⇒ Object
26
27
28
|
# File 'lib/eye/process/states_history.rb', line 26
def last_reason
last[:reason] rescue nil
end
|
#last_state ⇒ Object
22
23
24
|
# File 'lib/eye/process/states_history.rb', line 22
def last_state
last[:state]
end
|
#last_state_changed_at ⇒ Object
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
|
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
|