<commit_before>require 'mandrake/translator'
require 'rack'
require 'forwardable'

module Mandrake
  # Mandrake::Builder based on Rack::Builder
  # It adds :if and :unless options to the `use` method,
  # and enables conditional expression builders such as `env` and `request`
  # @example
  #   Mandrake::Builder.new do
  #     use Rack::Deflater, if:     request.path_info.start_with?("/deflater")
  #     use Rack::ETag,     unless: request.path_info.end_with?("etag")
  #     run ->(env){ [200, {'Content-Type' => 'text/plain'}, ["Hello World"]] }
  #   end
  class Builder < Rack::Builder
    extend Forwardable
    def_delegators :translator, :use, :request, :env

    # Converts to application by using Mandrake::Translator
    def to_app
      app = @map ? generate_map(@run, @map) : @run
      fail "missing run or map statement" unless app
      app = translator.translate.reverse.inject(app) do |application, middleware|
        middleware.call(application)
      end
      @warmup.call(app) if @warmup
      app
    end

    # This method is for delegating methods
    # Returns an instance of Mandrake::Translator for use in delegation and to_app
    # @return [Mandrake::Translator]
    def translator
      @translator ||= Translator.new
    end

    private :translator<commit_msg>Prefer Proc#[] over Proc#call in this case<commit_after>require 'mandrake/translator'
require 'rack'
require 'forwardable'

module Mandrake
  # Mandrake::Builder based on Rack::Builder
  # It adds :if and :unless options to the `use` method,
  # and enables conditional expression builders such as `env` and `request`
  # @example
  #   Mandrake::Builder.new do
  #     use Rack::Deflater, if:     request.path_info.start_with?("/deflater")
  #     use Rack::ETag,     unless: request.path_info.end_with?("etag")
  #     run ->(env){ [200, {'Content-Type' => 'text/plain'}, ["Hello World"]] }
  #   end
  class Builder < Rack::Builder
    extend Forwardable
    def_delegators :translator, :use, :request, :env

    # Converts to application by using Mandrake::Translator
    def to_app
      app = @map ? generate_map(@run, @map) : @run
      fail "missing run or map statement" unless app
      app = translator.translate.reverse.inject(app) do |application, middleware|
        middleware[application]
      end
      @warmup.call(app) if @warmup
      app
    end

    # This method is for delegating methods
    # Returns an instance of Mandrake::Translator for use in delegation and to_app
    # @return [Mandrake::Translator]
    def translator
      @translator ||= Translator.new
    end

    private :translator
{'fraction_non_alphanumeric': 0.10886172650878534, 'fraction_numerical': 0.002291825821237586, 'mean_word_length': 3.3504983388704317, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '4787831', 'n_tokens_mistral': 844, 'n_tokens_neox': 807, 'n_words': 245}