<commit_before>require "rack"
require "tilt"
require "cuba/version"

class Rack::Response
  # 301 Moved Permanently
  # 302 Found
  # 303 See Other
  # 307 Temporary Redirect
  def redirect(target, status = 302)
    self.status = status
    self["Location"] = target
  end
end

class Cuba
  class RedefinitionError < StandardError
  end

  @@methods = []

  def self.method_added(meth)
    @@methods << meth
  end

  def self.reset!
    @app = nil
    @prototype = nil
  end

  def self.app
    @app ||= Rack::Builder.new
  end

  def self.use(middleware, *args, &block)
    app.use(middleware, *args, &block)
  end

  def self.define(&block)
    app.run new(&block)
  end

  def self.build
    Class.new(self)
  end

  def self.prototype
    @prototype ||= app.to_app
  end

  def self.call(env)
    prototype.call(env)
  end

  attr :env
  attr :req
  attr :res
  attr :captures

  def initialize(&blk)
    @blk = blk
    @captures = []
  end

  def call(env)
    dup._call(env)
  end

  def _call(env)
    @env = env
    @req = Rack::Request.new(env)
    @res = Rack::Response.new

    # This `catch` statement will either receive a
    # rack response tuple via a `halt`, or will
    # fall back to issuing a 404.
    #
    # When it `catch`es a throw, the return value
    # of this whole `_call` method will be the
    # rack response tuple, which is exactly what we want.
    catch(:halt) do<commit_msg>Rename _call to call! (inspired from Sinatra).<commit_after>require "rack"
require "tilt"
require "cuba/version"

class Rack::Response
  # 301 Moved Permanently
  # 302 Found
  # 303 See Other
  # 307 Temporary Redirect
  def redirect(target, status = 302)
    self.status = status
    self["Location"] = target
  end
end

class Cuba
  class RedefinitionError < StandardError
  end

  @@methods = []

  def self.method_added(meth)
    @@methods << meth
  end

  def self.reset!
    @app = nil
    @prototype = nil
  end

  def self.app
    @app ||= Rack::Builder.new
  end

  def self.use(middleware, *args, &block)
    app.use(middleware, *args, &block)
  end

  def self.define(&block)
    app.run new(&block)
  end

  def self.build
    Class.new(self)
  end

  def self.prototype
    @prototype ||= app.to_app
  end

  def self.call(env)
    prototype.call(env)
  end

  attr :env
  attr :req
  attr :res
  attr :captures

  def initialize(&blk)
    @blk = blk
    @captures = []
  end

  def call(env)
    dup.call!(env)
  end

  def call!(env)
    @env = env
    @req = Rack::Request.new(env)
    @res = Rack::Response.new

    # This `catch` statement will either receive a
    # rack response tuple via a `halt`, or will
    # fall back to issuing a 404.
    #
    # When it `catch`es a throw, the return value
    # of this whole `_call` method will be the
    # rack response tuple, which is exactly what we want.
    catch(:halt) do
{'fraction_non_alphanumeric': 0.10655450403084472, 'fraction_numerical': 0.012618296529968454, 'mean_word_length': 2.6683804627249357, 'pattern_counts': {'":': 0, '<': 9, '<?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': '4684641', 'n_tokens_mistral': 1052, 'n_tokens_neox': 971, 'n_words': 311}