Module: RailsMetrics::Store::ClassMethods

Defined in:
lib/rails_metrics/store.rb

Instance Method Summary collapse

Instance Method Details

#events_to_metrics_tree(events) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rails_metrics/store.rb', line 36

def events_to_metrics_tree(events)
  verify_active_connections! if respond_to?(:verify_active_connections!)

  metrics = events.map do |event|
    metric = new
    metric.configure(event)
    metric
  end

  mount_tree(metrics)
end

#mount_tree(metrics) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/rails_metrics/store.rb', line 25

def mount_tree(metrics)
  while metric = metrics.shift
    if parent = metrics.find { |n| n.parent_of?(metric) }
      parent.children << metric
    elsif metrics.empty?
      return metric if metric.rack_request?
      raise %(Expected tree root to be a "rack.request", got #{metric.name.inspect})
    end
  end
end