<commit_before>require "turbo_urls/version"
require 'turbo_urls/cache'
require 'turbo_urls/railtie'

module TurboUrls
  module Interceptor; end
  @cache = Cache.new
  def self.cache() @cache end

  def self.i_m_your_turbo_lover!
    [Rails.application.routes.named_routes.path_helpers_module, Rails.application.routes.named_routes.url_helpers_module].each do |mod|
      mod.prepend TurboUrls::Interceptor
      def mod.method_added(meth)
        TurboUrls::Interceptor.module_eval do
          define_method meth, TurboUrls::CACHE_METHOD_BODY
        end
      end
    end
  end

  CACHE_METHOD_BODY = ->(*args) do
    if args.empty? || args.all? {|a| a.is_a?(Fixnum) || a.is_a?(String) }
      # do nothing
    elsif defined?(ActiveRecord::Base) && args.any? {|a| a.is_a? ActiveRecord::Base }
      args = args.map {|a| a.is_a?(ActiveRecord::Base) ? a.to_param : a }
    else
      return super(*args)
    end

    cached = TurboUrls.cache[__method__, args]
    return cached if cached

    url = super(*args)

    TurboUrls.cache[__method__, args] = url
  end
end<commit_msg>Let the Interceptor keep it's own Proc<commit_after>require "turbo_urls/version"
require 'turbo_urls/cache'
require 'turbo_urls/railtie'

module TurboUrls
  module Interceptor
    CACHE_LOOKUP = ->(*args) do
      if args.empty? || args.all? {|a| a.is_a?(Fixnum) || a.is_a?(String) }
        # do nothing
      elsif defined?(ActiveRecord::Base) && args.any? {|a| a.is_a? ActiveRecord::Base }
        args = args.map {|a| a.is_a?(ActiveRecord::Base) ? a.to_param : a }
      else
        return super(*args)
      end

      cached = TurboUrls.cache[__method__, args]
      return cached if cached

      url = super(*args)

      TurboUrls.cache[__method__, args] = url
    end
  end

  @cache = Cache.new
  def self.cache() @cache end

  def self.i_m_your_turbo_lover!
    [Rails.application.routes.named_routes.path_helpers_module, Rails.application.routes.named_routes.url_helpers_module].each do |mod|
      mod.prepend TurboUrls::Interceptor
      def mod.method_added(meth)
        TurboUrls::Interceptor.module_eval do
          define_method meth, TurboUrls::Interceptor::CACHE_LOOKUP
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.11307100859339665, 'fraction_numerical': 0.0, 'mean_word_length': 3.2456813819577737, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3901561', 'n_tokens_mistral': 793, 'n_tokens_neox': 790, 'n_words': 159}