class Rubevent::Metrics

Public Class Methods

new() click to toggle source
# File lib/rubevent/metrics.rb, line 3
def initialize
  @events_processed = {}
  @events_received = {}
  @listeners_registered = {}
end

Public Instance Methods

events_processed(event_type = nil) click to toggle source
# File lib/rubevent/metrics.rb, line 17
def events_processed(event_type = nil)
  calc_hash @events_processed, event_type
end
events_received(event_type = nil) click to toggle source
# File lib/rubevent/metrics.rb, line 13
def events_received(event_type = nil)
  calc_hash(@events_received, event_type)
end
loop_size(event_type = nil) click to toggle source
# File lib/rubevent/metrics.rb, line 9
def loop_size(event_type = nil)
   events_received(event_type) - events_processed(event_type)
end
mark_processed(event_type) click to toggle source
# File lib/rubevent/metrics.rb, line 25
def mark_processed event_type
  update_hash @events_processed, event_type
end
num_listeners(event_type = nil) click to toggle source
# File lib/rubevent/metrics.rb, line 21
def num_listeners(event_type = nil)
  calc_hash @listeners_registered, event_type
end
received(event_type) click to toggle source
# File lib/rubevent/metrics.rb, line 29
def received event_type
  update_hash @events_received, event_type
end
registered(event_type) click to toggle source
# File lib/rubevent/metrics.rb, line 33
def registered event_type
  update_hash @listeners_registered, event_type
end

Private Instance Methods

calc_hash(hash, key) click to toggle source
# File lib/rubevent/metrics.rb, line 46
def calc_hash(hash, key)
  if key
    hash[key] || 0
  else
    hash.values.reduce 0, :+
  end
end
update_hash(hash, key) click to toggle source
# File lib/rubevent/metrics.rb, line 38
def update_hash(hash, key)
  if hash[key]
    hash[key] += 1
  else
    hash[key] = 1
  end
end