<commit_before>module JSONAPIonify::Api
  module Base::AppBuilder

    def middleware
      @middleware ||= MiddlewareStack.new
    end

    def inherited(subclass)
      super(subclass)
      subclass.instance_exec(self) do |superclass|
        @middleware = superclass.middleware.dup
      end
    end

    def use(*args)
      middleware.use(*args)
    end

    def call(env)
      app.call(env)
    end

    private

    def app
      api = self
      Rack::Builder.new do
        use Rack::ShowExceptions
        use Rack::CommonLogger
        use Base::Reloader unless ENV['RACK_ENV'] == 'production'
        map "/docs" do
          run ->(env) {
            request = JSONAPIonify::Api::Server::Request.new env
            if request.path_info.present?
              return [301, { 'location' => request.path.chomp(request.path_info) }, []]
            end
            response = Rack::Response.new
            response.write api.documentation_output(request)
            response.finish
          }
        end
        map "/" do
          api.middleware.install(binding)
          run JSONAPIonify::Api::Server.new(api)
        end
      end
    end
  end
end<commit_msg>use self instead of a binding<commit_after>module JSONAPIonify::Api
  module Base::AppBuilder

    def middleware
      @middleware ||= MiddlewareStack.new
    end

    def inherited(subclass)
      super(subclass)
      subclass.instance_exec(self) do |superclass|
        @middleware = superclass.middleware.dup
      end
    end

    def use(*args)
      middleware.use(*args)
    end

    def call(env)
      app.call(env)
    end

    private

    def app
      api = self
      Rack::Builder.new do
        use Rack::ShowExceptions
        use Rack::CommonLogger
        use Base::Reloader unless ENV['RACK_ENV'] == 'production'
        map "/docs" do
          run ->(env) {
            request = JSONAPIonify::Api::Server::Request.new env
            if request.path_info.present?
              return [301, { 'location' => request.path.chomp(request.path_info) }, []]
            end
            response = Rack::Response.new
            response.write api.documentation_output(request)
            response.finish
          }
        end
        map "/" do
          api.middleware.install(self)
          run JSONAPIonify::Api::Server.new(api)
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.0968421052631579, 'fraction_numerical': 0.0025263157894736842, 'mean_word_length': 1.897560975609756, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4028827', 'n_tokens_mistral': 708, 'n_tokens_neox': 689, 'n_words': 152}