Sha256: 47911518779ff2fa59e4e8560aa11ec5b4e6f7983d63ac10ebbf94d4dbf9cbf6

Contents?: true

Size: 1012 Bytes

Versions: 80

Compression:

Stored size: 1012 Bytes

Contents

class Jets::Router
  class Finder
    extend Memoist

    def initialize(path, method)
      @path = path
      @method = method.to_s.upcase
    end

    def run
      reset_routes!
      # Precedence:
      # 1. Routes with no captures get highest precedence: posts/new
      # 2. Then we consider the routes with captures: post/:id
      #
      # Within these 2 groups we consider the routes with the longest path first
      # since posts/:id and posts/:id/edit can both match.
      routes = router.ordered_routes
      route = routes.find do |r|
        matcher.match?(r)
      end
      route
    end

  private

    attr_reader :path, :method

    # "hot reload" for development
    def reset_routes!
      return unless Jets.env.development?

      Jets::Router.clear!
      Jets.application.load_routes(refresh: true)
    end

    def matcher
      Jets::Router::Matcher.new(path, method)
    end
    memoize :matcher

    def router
      Jets.application.routes
    end
    memoize :router
  end
end

Version data entries

80 entries across 80 versions & 2 rubygems

Version Path
jets-2.3.6 lib/jets/router/finder.rb
jets-2.3.5 lib/jets/router/finder.rb
jets-2.3.4 lib/jets/router/finder.rb
jets-2.3.3 lib/jets/router/finder.rb
jets-2.3.2 lib/jets/router/finder.rb
jets-2.3.1 lib/jets/router/finder.rb
jets-2.3.0 lib/jets/router/finder.rb
jets-2.2.5 lib/jets/router/finder.rb
jets-2.2.4 lib/jets/router/finder.rb
jets-2.2.3 lib/jets/router/finder.rb
jets-2.2.2 lib/jets/router/finder.rb
jets-2.2.1 lib/jets/router/finder.rb
jets-2.2.0 lib/jets/router/finder.rb
jets-2.1.7 lib/jets/router/finder.rb
jets-2.1.6 lib/jets/router/finder.rb
jets-2.1.5 lib/jets/router/finder.rb
jets-2.1.4 lib/jets/router/finder.rb
jets-2.1.3 lib/jets/router/finder.rb
jets-2.1.2 lib/jets/router/finder.rb
jets-2.1.1 lib/jets/router/finder.rb