Sha256: 140acdd5067bd4e219a182f487f2a9cdd4b52f02b1a8e08ede2ce73896e06b4c

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

require "nunes/subscriber"

module Nunes
  module Subscribers
    class ActionView < ::Nunes::Subscriber
      # Private
      Pattern = /\.action_view\Z/

      # Private: The namespace for events to subscribe to.
      def self.pattern
        Pattern
      end

      def render_template(start, ending, transaction_id, payload)
        instrument_identifier payload[:identifier], start, ending
      end

      def render_partial(start, ending, transaction_id, payload)
        instrument_identifier payload[:identifier], start, ending
      end

      private

      # Private: Sends timing information about identifier event.
      def instrument_identifier(identifier, start, ending)
        if identifier.present?
          runtime = ((ending - start) * 1_000).round
          timing identifier_to_metric(identifier), runtime
        end
      end

      # Private: Converts an identifier to a metric name. Strips out the rails
      # root from the full path.
      #
      # identifier - The String full path to the template or partial.
      def identifier_to_metric(identifier)
        rails_root = ::Rails.root.to_s + '/'
        view_path = identifier.gsub(rails_root, '')
        metric = view_path.gsub('/', '.')
        "action_view.#{metric}"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nunes-0.1.0 lib/nunes/subscribers/action_view.rb