<commit_before>require 'rack'

module Nancy
  class Base
    class << self
      %w(GET POST PATCH PUT DELETE HEAD OPTIONS).each do |verb|
        define_method(verb.downcase) do |pattern, &block|
          route_set[verb] << [compile(pattern), block]
        end
      end
    end

    def self.compile(pattern)
      keys = []
      pattern.gsub!(/(:\w+)/) do |match|
        keys << $1[1..-1]
        "([^/?#]+)"
      end
      [%r{^#{pattern}$}, keys]
    end

    def self.route_set
      @route_set ||= Hash.new { |h, k| h[k] = [] }
    end

    %w(request response params env).each do |accessor|
      define_method(accessor){ Thread.current[accessor.to_sym] }
    end

    def session
      request.env["rack.session"] || raise("Rack::Session handler is missing")
    end

    def redirect(uri)
      halt 302, {"Location" => uri}
    end

    def self.use(*args, &block)
      @builder.use(*args, &block)
    end

    def self.map(*args, &block)
      @builder.map(*args, &block)
    end

    def self.inherited(child)
      child.instance_eval do
        @builder = Rack::Builder.new
        @builder.run(child.new)
      end
    end

    def self.call(env)
      @builder.to_app.dup.call(env)
    end

    def call(env)
      Thread.current[:request] = Rack::Request.new(env)<commit_msg>Revert "Use @builder.to_app in Nancy::Base.call"<commit_after>require 'rack'

module Nancy
  class Base
    class << self
      %w(GET POST PATCH PUT DELETE HEAD OPTIONS).each do |verb|
        define_method(verb.downcase) do |pattern, &block|
          route_set[verb] << [compile(pattern), block]
        end
      end
    end

    def self.compile(pattern)
      keys = []
      pattern.gsub!(/(:\w+)/) do |match|
        keys << $1[1..-1]
        "([^/?#]+)"
      end
      [%r{^#{pattern}$}, keys]
    end

    def self.route_set
      @route_set ||= Hash.new { |h, k| h[k] = [] }
    end

    %w(request response params env).each do |accessor|
      define_method(accessor){ Thread.current[accessor.to_sym] }
    end

    def session
      request.env["rack.session"] || raise("Rack::Session handler is missing")
    end

    def redirect(uri)
      halt 302, {"Location" => uri}
    end

    def self.use(*args, &block)
      @builder.use(*args, &block)
    end

    def self.map(*args, &block)
      @builder.map(*args, &block)
    end

    def self.inherited(child)
      child.instance_eval do
        @builder = Rack::Builder.new
        @builder.run(child.new)
      end
    end

    def self.call(env)
      @builder.dup.call(env)
    end

    def call(env)
      Thread.current[:request] = Rack::Request.new(env)
{'fraction_non_alphanumeric': 0.1485148514851485, 'fraction_numerical': 0.00456968773800457, 'mean_word_length': 2.267412935323383, 'pattern_counts': {'":': 0, '<': 15, '<?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': '4778003', 'n_tokens_mistral': 928, 'n_tokens_neox': 886, 'n_words': 203}