Sha256: 107893fb31f2b233dd7065676d149734c7fec16e518b536be01a7622db4ddd0e

Contents?: true

Size: 768 Bytes

Versions: 6

Compression:

Stored size: 768 Bytes

Contents

module SystemMetrics
  class Store

    def save(events)
      return unless events.present?
      root_event = SystemMetrics::NestedEvent.arrange(events, :presort => false)
      root_model = create_metric(root_event)
      root_model.update_attributes(:request_id => root_model.id)
      save_tree(root_event.children, root_model.id, root_model.id)
    end

    private

      def save_tree(events, request_id, parent_id)
        events.each do |event|
          model = create_metric(event, :request_id => request_id, :parent_id => parent_id)
          save_tree(event.children, request_id, model.id)
        end
      end

      def create_metric(event, merge_params={})
        SystemMetrics::Metric.create(event.to_hash.merge(merge_params))
      end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
system-metrics-0.2.5 lib/system_metrics/store.rb
system-metrics-0.2.4 lib/system_metrics/store.rb
system-metrics-0.2.3 lib/system_metrics/store.rb
system-metrics-0.2.2 lib/system_metrics/store.rb
system-metrics-0.2.1 lib/system_metrics/store.rb
system-metrics-0.2.0 lib/system_metrics/store.rb