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-4.0.12 lib/jets/router/finder.rb
jets-4.0.11 lib/jets/router/finder.rb
jets-4.0.10 lib/jets/router/finder.rb
jets-4.0.9 lib/jets/router/finder.rb
jets-4.0.8 lib/jets/router/finder.rb
jets-4.0.7 lib/jets/router/finder.rb
jets-4.0.6 lib/jets/router/finder.rb
jets-4.0.5 lib/jets/router/finder.rb
jets-4.0.4 lib/jets/router/finder.rb
jets-4.0.3 lib/jets/router/finder.rb
jets-4.0.2 lib/jets/router/finder.rb
jets-4.0.1 lib/jets/router/finder.rb
jets-4.0.0 lib/jets/router/finder.rb
jets-3.2.2 lib/jets/router/finder.rb
jets-3.2.1 lib/jets/router/finder.rb
jets.benforeva-3.0.17.pre.mount.pre.fix lib/jets/router/finder.rb
jets-3.2.0 lib/jets/router/finder.rb
jets-3.1.5 lib/jets/router/finder.rb
jets-3.1.4 lib/jets/router/finder.rb
jets-3.1.3 lib/jets/router/finder.rb