<commit_before>module Opal
  class SourceMapServer
    # Carelessly taken from Sprockets::Caching (Sprockets v2)
    class Cache
      def initialize
        @cache = {}
      end

      attr_reader :cache

      def cache_get(key)
        # `Cache#get(key)` for Memcache
        if cache.respond_to?(:get)
          cache.get(key)

        # `Cache#[key]` so `Hash` can be used
        elsif cache.respond_to?(:[])
          cache[key]

        # `Cache#read(key)` for `ActiveSupport::Cache` support
        elsif cache.respond_to?(:read)
          cache.read(key)

        else
          nil
        end
      end

      def cache_set(key, value)
        # `Cache#set(key, value)` for Memcache
        if cache.respond_to?(:set)
          cache.set(key, value)

        # `Cache#[key]=value` so `Hash` can be used
        elsif cache.respond_to?(:[]=)
          cache[key] = value

        # `Cache#write(key, value)` for `ActiveSupport::Cache` support
        elsif cache.respond_to?(:write)
          cache.write(key, value)
        end

        value
      end
    end

    def self.get_map_cache(sprockets, logical_path)
      cache_key = cache_key_for_path(logical_path)
      cache(sprockets).cache_get(cache_key)
    end

    def self.set_map_cache(sprockets, logical_path, map_contents)
      cache_key = cache_key_for_path(logical_path)
      cache(sprockets).cache_set(cache_key, map_contents)
    end

    def self.cache(sprockets)
      @cache ||= sprockets.cache ? sprockets : Cache.new
    end

    def self.cache_key_for_path(logical_path)
      base_name = logical_path.gsub(/\.js$/, '')
      File.join('opal', 'source_maps', base_name)
    end


    def initialize sprockets, prefix = '/'
      @sprockets = sprockets<commit_msg>Fix the cache key for source maps<commit_after>module Opal
  class SourceMapServer
    # Carelessly taken from Sprockets::Caching (Sprockets v2)
    class Cache
      def initialize
        @cache = {}
      end

      attr_reader :cache

      def cache_get(key)
        # `Cache#get(key)` for Memcache
        if cache.respond_to?(:get)
          cache.get(key)

        # `Cache#[key]` so `Hash` can be used
        elsif cache.respond_to?(:[])
          cache[key]

        # `Cache#read(key)` for `ActiveSupport::Cache` support
        elsif cache.respond_to?(:read)
          cache.read(key)

        else
          nil
        end
      end

      def cache_set(key, value)
        # `Cache#set(key, value)` for Memcache
        if cache.respond_to?(:set)
          cache.set(key, value)

        # `Cache#[key]=value` so `Hash` can be used
        elsif cache.respond_to?(:[]=)
          cache[key] = value

        # `Cache#write(key, value)` for `ActiveSupport::Cache` support
        elsif cache.respond_to?(:write)
          cache.write(key, value)
        end

        value
      end
    end

    def self.get_map_cache(sprockets, logical_path)
      logical_path = logical_path.gsub(/\.js$/, '')
      cache_key = cache_key_for_path(logical_path+'.map')
      cache(sprockets).cache_get(cache_key)
    end

    def self.set_map_cache(sprockets, logical_path, map_contents)
      logical_path = logical_path.gsub(/\.js$/, '')
      cache_key = cache_key_for_path(logical_path+'.map')
      cache(sprockets).cache_set(cache_key, map_contents)
    end

    def self.cache(sprockets)
      @cache ||= sprockets.cache ? sprockets : Cache.new
    end

    def self.cache_key_for_path(logical_path)
      base_name = logical_path.gsub(/\.js$/, '')
      File.join('opal', 'source_maps', base_name)
    end


    def initialize sprockets, prefix = '/'
      @sprockets = sprockets
{'fraction_non_alphanumeric': 0.11386138613861387, 'fraction_numerical': 0.00055005500550055, 'mean_word_length': 2.358264081255771, 'pattern_counts': {'":': 0, '<': 3, '<?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': '961791', 'n_tokens_mistral': 1235, 'n_tokens_neox': 1208, 'n_words': 243}