<commit_before>require 'http_router'
require 'lotus/routing/endpoint_resolver'
require 'lotus/routing/route'
require 'lotus/routing/namespace'
require 'lotus/routing/resource'
require 'lotus/routing/resources'

HttpRouter::Route::VALID_HTTP_VERBS = %w{GET POST PUT PATCH DELETE HEAD OPTIONS TRACE}

module Lotus
  class Router < HttpRouter
    VERSION = '0.0.1'

    attr_reader :resolver

    def self.draw(options = {}, &blk)
      new(options).tap {|r| r.instance_eval(&blk) }
    end

    def initialize(options = {})
      super

      @default_scheme = options[:scheme]   if options[:scheme]
      @default_host   = options[:host]     if options[:host]
      @default_port   = options[:port]     if options[:port]
      @resolver       = options[:resolver] || Routing::EndpointResolver.new
      @route_class    = options[:route]    || Routing::Route
    end

    def redirect(path, options = {}, &endpoint)
      get(path).redirect resolver.find(options), options[:code] || 302
    end

    def namespace(name, &blk)
      Routing::Namespace.new(self, name, &blk)
    end

    def resource(name, options = {}, &blk)
      Routing::Resource.new(self, name, options, &blk)
    end

    def resources(name, options = {}, &blk)
      Routing::Resources.new(self, name, options, &blk)
    end

    def pass_on_response(response) #:api: private
      super response.to_a
    end

    def no_response(request, env) #:api: private
      if request.acceptable_methods.any? && !request.acceptable_methods.include?(env['REQUEST_METHOD'])
        [405, {'Allow' => request.acceptable_methods.sort.join(", ")}, []]
      else
        @default_app.call(env)
      end
    end

    private
    def add_with_request_method(path, method, opts = {}, &app)
      super.generate(resolver, opts, &app)
    end
  end
end<commit_msg>Don't reset default app<commit_after>require 'http_router'
require 'lotus/routing/endpoint_resolver'
require 'lotus/routing/route'
require 'lotus/routing/namespace'
require 'lotus/routing/resource'
require 'lotus/routing/resources'

HttpRouter::Route::VALID_HTTP_VERBS = %w{GET POST PUT PATCH DELETE HEAD OPTIONS TRACE}

module Lotus
  class Router < HttpRouter
    VERSION = '0.0.1'

    attr_reader :resolver

    def self.draw(options = {}, &blk)
      new(options).tap {|r| r.instance_eval(&blk) }
    end

    def initialize(options = {})
      super

      @default_scheme = options[:scheme]   if options[:scheme]
      @default_host   = options[:host]     if options[:host]
      @default_port   = options[:port]     if options[:port]
      @resolver       = options[:resolver] || Routing::EndpointResolver.new
      @route_class    = options[:route]    || Routing::Route
    end

    def redirect(path, options = {}, &endpoint)
      get(path).redirect resolver.find(options), options[:code] || 302
    end

    def namespace(name, &blk)
      Routing::Namespace.new(self, name, &blk)
    end

    def resource(name, options = {}, &blk)
      Routing::Resource.new(self, name, options, &blk)
    end

    def resources(name, options = {}, &blk)
      Routing::Resources.new(self, name, options, &blk)
    end

    def reset! #:api: private
      uncompile
      @routes, @named_routes, @root = [], Hash.new{|h,k| h[k] = []}, Node::Root.new(self)
    end

    def pass_on_response(response) #:api: private
      super response.to_a
    end

    def no_response(request, env) #:api: private
      if request.acceptable_methods.any? && !request.acceptable_methods.include?(env['REQUEST_METHOD'])
        [405, {'Allow' => request.acceptable_methods.sort.join(", ")}, []]
      else
        @default_app.call(env)
      end
    end

    private
    def add_with_request_method(path, method, opts = {}, &app)
      super.generate(resolver, opts, &app)
    end
  end
end
{'fraction_non_alphanumeric': 0.1343362364740037, 'fraction_numerical': 0.004750593824228029, 'mean_word_length': 3.2536475869809203, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6301294', 'n_tokens_mistral': 1236, 'n_tokens_neox': 1202, 'n_words': 268}