<commit_before>require "singleton"

module RogerBabeljs
  # Middleware
  #
  # Middleware to do on the fly BabelJS conversion
  class Middleware
    # @option options [Array] :match Array of regexp's to match URLS
    #   that should run through babel. Default: [/\A\/javascripts\/src\/.*\.js\Z/]
    # @option options [Hash] :babel_options Options to pass to babel.
    def initialize(app, options = {})
      @app = app

      @options = {
        match: [%r{\A/javascripts/src/.*\.js\Z}],
        babel_options: {}
      }.update(options)
    end

    def call(env)
      # See if any URL matches PATH_INFO
      if url_matches?(env["PATH_INFO"])
        status, headers, body = @app.call(env)

        if status == 200

          # We must use "each" here as we cannot know what we get form the chain.
          # Rack defines that it must at least have an .each method.
          body_str = []
          body.each { |f| body_str << f }
          body_str = body_str.join

          build_es5_response(env["PATH_INFO"], body_str, status, headers)
        else<commit_msg>Assign PATH_INFO to local variable before passing env on to rest of rack stack<commit_after>require "singleton"

module RogerBabeljs
  # Middleware
  #
  # Middleware to do on the fly BabelJS conversion
  class Middleware
    # @option options [Array] :match Array of regexp's to match URLS
    #   that should run through babel. Default: [/\A\/javascripts\/src\/.*\.js\Z/]
    # @option options [Hash] :babel_options Options to pass to babel.
    def initialize(app, options = {})
      @app = app

      @options = {
        match: [%r{\A/javascripts/src/.*\.js\Z}],
        babel_options: {}
      }.update(options)
    end

    def call(env)
      # See if any URL matches PATH_INFO
      if url_matches?(env["PATH_INFO"])
        # Assign it to local variable here; sometimes middleware changes the environment
        # deeper down the callstack.
        url = env["PATH_INFO"]
        status, headers, body = @app.call(env)

        if status == 200

          # We must use "each" here as we cannot know what we get form the chain.
          # Rack defines that it must at least have an .each method.
          body_str = []
          body.each { |f| body_str << f }
          body_str = body_str.join

          build_es5_response(url, body_str, status, headers)
        else
{'fraction_non_alphanumeric': 0.10385756676557864, 'fraction_numerical': 0.003391267486222976, 'mean_word_length': 2.291492329149233, 'pattern_counts': {'":': 0, '<': 7, '<?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': '3806906', 'n_tokens_mistral': 731, 'n_tokens_neox': 703, 'n_words': 245}