<commit_before>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 + File::SEPARATOR
        view_path = identifier.gsub(rails_root, '')
        "action_view.#{view_path}" if view_path
      end
    end
  end
end
<commit_msg>Just do nil check instead of presence check.<commit_after>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
          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 + File::SEPARATOR
        view_path = identifier.gsub(rails_root, '')
        "action_view.#{view_path}" if view_path
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.07126524390243902, 'fraction_numerical': 0.003048780487804878, 'mean_word_length': 2.5860655737704916, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1064439', 'n_tokens_mistral': 705, 'n_tokens_neox': 682, 'n_words': 223}