class Healthyr::Event

Attributes

event[RW]

Public Class Methods

new(*args) click to toggle source
# File lib/healthyr/event.rb, line 5
def initialize(*args)
  @event = ActiveSupport::Notifications::Event.new(*args)
end

Public Instance Methods

to_hash() click to toggle source
# File lib/healthyr/event.rb, line 9
def to_hash
  {reported_at: Time.at(event.time), time: {total: event.duration}}.tap do |hash|
    if database?
      hash[:name] = 'database'
      hash[:value] = payload[:sql]
    elsif view?
      hash[:name] = 'view'
      hash[:value] = payload[:virtual_path]
    elsif controller?
      hash[:name] = 'controller'
      hash[:value] = "#{payload[:controller]}##{payload[:action]}"
      hash[:time][:view] = payload[:view_runtime]
      hash[:time][:db] = payload[:db_runtime]
    end
  end
end

Private Instance Methods

controller?() click to toggle source
# File lib/healthyr/event.rb, line 39
def controller?
  event.name == 'process_action.action_controller'
end
database?() click to toggle source
# File lib/healthyr/event.rb, line 31
def database?
  event.name == 'sql.active_record'
end
payload() click to toggle source
# File lib/healthyr/event.rb, line 27
def payload
  @payload ||= event.payload
end
view?() click to toggle source
# File lib/healthyr/event.rb, line 35
def view?
  event.name == '!render_template.action_view'
end