Sha256: 9b45b20a088e3a9a0b595114ce4943e8f98029c68879688241428cd0ee43eec4

Contents?: true

Size: 659 Bytes

Versions: 11

Compression:

Stored size: 659 Bytes

Contents

class Eye::Process::StatesHistory < Eye::Utils::Tail

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

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

  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

  def last_state
    last[:state]
  end

  def last_reason
    last[:reason] rescue nil
  end

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

end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
eye-0.10.1.pre lib/eye/process/states_history.rb
eye-0.10.0 lib/eye/process/states_history.rb
eye-0.10.0.alpha2 lib/eye/process/states_history.rb
eye-0.10.0.alpha lib/eye/process/states_history.rb
eye-0.9.4.nosigar lib/eye/process/states_history.rb
eye-0.9.4 lib/eye/process/states_history.rb
eye-0.9.3 lib/eye/process/states_history.rb
eye-0.9.2.nosigar lib/eye/process/states_history.rb
eye-0.9.2 lib/eye/process/states_history.rb
eye-0.9.1 lib/eye/process/states_history.rb
eye-0.9.pre lib/eye/process/states_history.rb