<commit_before>require 'concurrent/map'
require 'action_view/dependency_tracker'
require 'monitor'

module ActionView
  class Digestor
    cattr_reader(:cache)
    @@cache          = Concurrent::Map.new
    @@digest_mutex   = Mutex.new

    class PerRequestDigestCacheExpiry < Struct.new(:app) # :nodoc:
      def call(env)
        ActionView::Digestor.cache.clear
        app.call(env)
      end
    end

    class << self
      # Supported options:
      #
      # * <tt>name</tt>   - Template name
      # * <tt>finder</tt>  - An instance of <tt>ActionView::LookupContext</tt>
      # * <tt>dependencies</tt>  - An array of dependent views
      # * <tt>partial</tt>  - Specifies whether the template is a partial
      def digest(name:, finder:, **options)
        options.assert_valid_keys(:dependencies, :partial)

        dependencies = Array.wrap(options[:dependencies])
        cache_key = ([ name, finder.details_key.hash ].compact + dependencies).join('.')

        # this is a correctly done double-checked locking idiom
        # (Concurrent::Map's lookups have volatile semantics)
        @@cache[cache_key] || @@digest_mutex.synchronize do
          @@cache.fetch(cache_key) do # re-check under lock
            @@cache[cache_key] = tree(name, finder, dependencies).digest
          end
        end
      end

      def logger
        ActionView::Base.logger || NullLogger
      end

      # Create a dependency tree for template named +name+.
      def tree(name, finder, injected = [], partial = false, seen = {})
        logical_name = name.gsub(%r|/_|, "/")
        partial = partial || name.include?("/_")

        if finder.disable_cache { finder.exists?(logical_name, [], partial) }
          template = finder.disable_cache { finder.find(logical_name, [], partial) }<commit_msg>convert `digest` to only use kwargs<commit_after>require 'concurrent/map'
require 'action_view/dependency_tracker'
require 'monitor'

module ActionView
  class Digestor
    cattr_reader(:cache)
    @@cache          = Concurrent::Map.new
    @@digest_mutex   = Mutex.new

    class PerRequestDigestCacheExpiry < Struct.new(:app) # :nodoc:
      def call(env)
        ActionView::Digestor.cache.clear
        app.call(env)
      end
    end

    class << self
      # Supported options:
      #
      # * <tt>name</tt>   - Template name
      # * <tt>finder</tt>  - An instance of <tt>ActionView::LookupContext</tt>
      # * <tt>dependencies</tt>  - An array of dependent views
      # * <tt>partial</tt>  - Specifies whether the template is a partial
      def digest(name:, finder:, dependencies: [])
        dependencies ||= []
        cache_key = ([ name, finder.details_key.hash ].compact + dependencies).join('.')

        # this is a correctly done double-checked locking idiom
        # (Concurrent::Map's lookups have volatile semantics)
        @@cache[cache_key] || @@digest_mutex.synchronize do
          @@cache.fetch(cache_key) do # re-check under lock
            @@cache[cache_key] = tree(name, finder, dependencies).digest
          end
        end
      end

      def logger
        ActionView::Base.logger || NullLogger
      end

      # Create a dependency tree for template named +name+.
      def tree(name, finder, injected = [], partial = false, seen = {})
        logical_name = name.gsub(%r|/_|, "/")
        partial = partial || name.include?("/_")

        if finder.disable_cache { finder.exists?(logical_name, [], partial) }
          template = finder.disable_cache { finder.find(logical_name, [], partial) }
{'fraction_non_alphanumeric': 0.12397627788760238, 'fraction_numerical': 0.0, 'mean_word_length': 2.6365503080082138, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 23, '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': '2873184', 'n_tokens_mistral': 1084, 'n_tokens_neox': 1022, 'n_words': 252}