Sha256: 6a5ee45642368cdc8d8b81bc6ddfd9501e5f8b778dc85bbdb34e3684170bb08d

Contents?: true

Size: 1.59 KB

Versions: 1

Compression:

Stored size: 1.59 KB

Contents

require 'tracebin/helpers'

module Tracebin
  class Event
    include Tracebin::Helpers

    attr_reader :event

    def initialize(event)
      @event = event
    end

    def recorder_type
      event[0]
    end

    def valid?
      true
    end

    def data_hash
      {
        event_type: type,
        start: time_to_string(event[1]),
        stop: time_to_string(event[2]),
        duration: milliseconds_between(event[2], event[1]),
        data: select_data || event.last
      }
    end
  end

  class SQLEvent < Event
    def valid?
      event.last[:name] != "SCHEMA"
    end

    private

    def type
      :sql
    end

    def select_data
      {
        sql: event.last[:sql],
        name: event.last[:name],
        statement_name: event.last[:statement_name]
      }
    end
  end

  class ControllerEvent < Event
    private

    def type
      :controller_action
    end

    def select_data
      {
        controller: event.last[:controller],
        action: event.last[:action],
        format: event.last[:format],
        method: event.last[:method],
        path: event.last[:path],
        status: event.last[:status],
        view_runtime: event.last[:view_runtime],
        db_runtime: event.last[:db_runtime]
      }
    end
  end

  class ViewEvent < Event
    private

    def type
      :view
    end

    def select_data
      nil
    end
  end

  class SinatraEvent < Event
    private

    def type
      :route
    end

    def select_data
      nil
    end
  end

  class CustomEvent < Event
    private

    def type
      :other
    end

    def select_data
      nil
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tracebin-0.0.13 lib/tracebin/events.rb