Class: Wayfarer::Routing::PathFinder Private
- Inherits:
-
Object
- Object
- Wayfarer::Routing::PathFinder
- Includes:
- KV
- Defined in:
- lib/wayfarer/routing/path_finder.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Encapsulates all state needed to route a URL.
Instance Attribute Summary collapse
- #action ⇒ Object? readonly private
- #current_path ⇒ Array<Wayfarer::Routing::Route> readonly private
- #found_path ⇒ Array<Wayfarer::Routing::Route> readonly private
- #params ⇒ Hash readonly private
- #params_stack ⇒ Wayfarer::Routing::HashStack readonly private
- #path ⇒ String readonly private
- #path_consumer ⇒ Wayfarer::Routing::PathConsumer readonly private
- #task ⇒ Wayfarer::Task readonly private
- #uri ⇒ Addressable::URI readonly private
Class Method Summary collapse
-
.result(route, task) ⇒ Result::Match, Result::Mismatch
private
The result of traversing the route with a new PathFinder for
url. -
.sub_result(route, path_finder) ⇒ Result::Match, Result::Mismatch
private
The result of traversing the route with an existing PathFinder.
Instance Method Summary collapse
- #current_route ⇒ Wayfarer::Routing::Route? private
-
#enter(route) ⇒ void
private
Enters a route node, updating state.
-
#found? ⇒ Boolean
private
Whether a route has matched and consumed the URL.
-
#initialize(task, path_consumer: initial_path_consumer(task[:uri]), params_stack: Wayfarer::Routing::HashStack.empty, stop_when_found: true, &callback) ⇒ PathFinder
constructor
private
A new instance of PathFinder.
-
#leave ⇒ void
private
Leaves the current route, restoring previous state.
-
#stopped? ⇒ Boolean
private
Whether traversal should stop.
-
#visit(route) ⇒ Boolean
private
Visits a Route.
Methods included from KV
Constructor Details
#initialize(task, path_consumer: initial_path_consumer(task[:uri]), params_stack: Wayfarer::Routing::HashStack.empty, stop_when_found: true, &callback) ⇒ PathFinder
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of PathFinder.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/wayfarer/routing/path_finder.rb', line 68 def initialize( task, path_consumer: initial_path_consumer(task[:uri]), params_stack: Wayfarer::Routing::HashStack.empty, stop_when_found: true, &callback ) @task = task @uri = task[:uri] @current_path = [] @actions = [] @path_consumer = path_consumer @params_stack = params_stack @kv = kv @callback = callback @stop_when_found = stop_when_found @match_history = [] end |
Instance Attribute Details
#action ⇒ Object?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
56 57 58 |
# File 'lib/wayfarer/routing/path_finder.rb', line 56 def action @action end |
#current_path ⇒ Array<Wayfarer::Routing::Route> (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
53 54 55 |
# File 'lib/wayfarer/routing/path_finder.rb', line 53 def current_path @current_path end |
#found_path ⇒ Array<Wayfarer::Routing::Route>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
53 54 55 |
# File 'lib/wayfarer/routing/path_finder.rb', line 53 def found_path @found_path end |
#params ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
59 60 61 |
# File 'lib/wayfarer/routing/path_finder.rb', line 59 def params @params end |
#params_stack ⇒ Wayfarer::Routing::HashStack (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
62 63 64 |
# File 'lib/wayfarer/routing/path_finder.rb', line 62 def params_stack @params_stack end |
#path ⇒ String (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
47 48 49 |
# File 'lib/wayfarer/routing/path_finder.rb', line 47 def path @path end |
#path_consumer ⇒ Wayfarer::Routing::PathConsumer (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
50 51 52 |
# File 'lib/wayfarer/routing/path_finder.rb', line 50 def path_consumer @path_consumer end |
#task ⇒ Wayfarer::Task (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
41 42 43 |
# File 'lib/wayfarer/routing/path_finder.rb', line 41 def task @task end |
#uri ⇒ Addressable::URI (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
44 45 46 |
# File 'lib/wayfarer/routing/path_finder.rb', line 44 def uri @uri end |
Class Method Details
.result(route, task) ⇒ Result::Match, Result::Mismatch
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The result of traversing the route with a new Wayfarer::Routing::PathFinder for url.
17 18 19 |
# File 'lib/wayfarer/routing/path_finder.rb', line 17 def self.result(route, task, &) accept_finder(route, new(task, &)) end |
.sub_result(route, path_finder) ⇒ Result::Match, Result::Mismatch
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The result of traversing the route with an existing Wayfarer::Routing::PathFinder.
26 27 28 |
# File 'lib/wayfarer/routing/path_finder.rb', line 26 def self.sub_result(route, path_finder) accept_finder(route, path_finder) end |
Instance Method Details
#current_route ⇒ Wayfarer::Routing::Route?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
95 96 97 |
# File 'lib/wayfarer/routing/path_finder.rb', line 95 def current_route current_path.last end |
#enter(route) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Enters a route node, updating state.
103 104 105 106 107 108 109 110 111 |
# File 'lib/wayfarer/routing/path_finder.rb', line 103 def enter(route) return if stopped? current_path.push(route) path_consumer.push(route) params_stack.push(route.params(self)) actions.prepend(route.action(self)) match_history.push(match(route)) end |
#found? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Whether a route has matched and consumed the URL.
90 91 92 |
# File 'lib/wayfarer/routing/path_finder.rb', line 90 def found? !!found_path end |
#leave ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Leaves the current route, restoring previous state.
116 117 118 119 120 121 122 123 124 |
# File 'lib/wayfarer/routing/path_finder.rb', line 116 def leave return if found? && stop_when_found? actions.pop params_stack.pop path_consumer.pop current_path.pop match_history.pop end |
#stopped? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Whether traversal should stop.
142 143 144 |
# File 'lib/wayfarer/routing/path_finder.rb', line 142 def stopped? found? && stop_when_found? end |
#visit(route) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Visits a Route.
130 131 132 133 134 135 136 137 |
# File 'lib/wayfarer/routing/path_finder.rb', line 130 def visit(route) return false if stopped? || !match_history.last return true unless route.leaf? && path_consumer.valid? found! if !found? && match_history.all? !stop_when_found? end |