Sha256: d50117e8a349eae48050cc59bb46f11b5f193e60689e1f452e68f40a5566979e

Contents?: true

Size: 664 Bytes

Versions: 4

Compression:

Stored size: 664 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| block.call(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

4 entries across 4 versions & 1 rubygems

Version Path
eye-0.8.1 lib/eye/process/states_history.rb
eye-0.8.celluloid15 lib/eye/process/states_history.rb
eye-0.8 lib/eye/process/states_history.rb
eye-0.8.rc lib/eye/process/states_history.rb