Class: ActionDispatch::Journey::Routes
- Inherits:
-
Object
- Object
- ActionDispatch::Journey::Routes
- Includes:
- Enumerable
- Defined in:
- lib/action_dispatch/journey/routes.rb
Overview
The Routing table. Contains all routes for a system. Routes can be added to the table by calling Routes#add_route.
Instance Attribute Summary collapse
-
#anchored_routes ⇒ Object
readonly
Returns the value of attribute anchored_routes.
-
#custom_routes ⇒ Object
readonly
Returns the value of attribute custom_routes.
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
Instance Method Summary collapse
- #add_route(name, mapping) ⇒ Object
- #ast ⇒ Object
- #clear ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(routes = []) ⇒ Routes
constructor
A new instance of Routes.
- #last ⇒ Object
- #length ⇒ Object (also: #size)
- #partition_route(route) ⇒ Object
- #simulator ⇒ Object
Constructor Details
#initialize(routes = []) ⇒ Routes
Returns a new instance of Routes.
14 15 16 17 18 19 20 |
# File 'lib/action_dispatch/journey/routes.rb', line 14 def initialize(routes = []) @routes = routes @ast = nil @anchored_routes = [] @custom_routes = [] @simulator = nil end |
Instance Attribute Details
#anchored_routes ⇒ Object (readonly)
Returns the value of attribute anchored_routes.
12 13 14 |
# File 'lib/action_dispatch/journey/routes.rb', line 12 def anchored_routes @anchored_routes end |
#custom_routes ⇒ Object (readonly)
Returns the value of attribute custom_routes.
12 13 14 |
# File 'lib/action_dispatch/journey/routes.rb', line 12 def custom_routes @custom_routes end |
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
12 13 14 |
# File 'lib/action_dispatch/journey/routes.rb', line 12 def routes @routes end |
Instance Method Details
#add_route(name, mapping) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/action_dispatch/journey/routes.rb', line 67 def add_route(name, mapping) route = mapping.make_route name, routes.length routes << route partition_route(route) clear_cache! route end |
#ast ⇒ Object
53 54 55 56 57 58 |
# File 'lib/action_dispatch/journey/routes.rb', line 53 def ast @ast ||= begin nodes = anchored_routes.map(&:ast) Nodes::Or.new(nodes) end end |
#clear ⇒ Object
39 40 41 42 43 |
# File 'lib/action_dispatch/journey/routes.rb', line 39 def clear routes.clear anchored_routes.clear custom_routes.clear end |
#each(&block) ⇒ Object
35 36 37 |
# File 'lib/action_dispatch/journey/routes.rb', line 35 def each(&block) routes.each(&block) end |
#empty? ⇒ Boolean
22 23 24 |
# File 'lib/action_dispatch/journey/routes.rb', line 22 def empty? routes.empty? end |
#last ⇒ Object
31 32 33 |
# File 'lib/action_dispatch/journey/routes.rb', line 31 def last routes.last end |
#length ⇒ Object Also known as: size
26 27 28 |
# File 'lib/action_dispatch/journey/routes.rb', line 26 def length routes.length end |
#partition_route(route) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/action_dispatch/journey/routes.rb', line 45 def partition_route(route) if route.path.anchored && route.path.requirements_anchored? anchored_routes << route else custom_routes << route end end |