Class: ActionDispatch::Journey::Routes
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
Instance Method Summary
collapse
Methods included from Enumerable
#as_json, #compact_blank, #exclude?, #excluding, #including, #index_by, #index_with, #many?, #pluck, #sum, #without
Constructor Details
#initialize ⇒ Routes
Returns a new instance of Routes.
12
13
14
15
16
17
18
|
# File 'actionpack/lib/action_dispatch/journey/routes.rb', line 12
def initialize
@routes = []
@ast = nil
@anchored_routes = []
@custom_routes = []
@simulator = nil
end
|
Instance Attribute Details
#anchored_routes ⇒ Object
Returns the value of attribute anchored_routes
10
11
12
|
# File 'actionpack/lib/action_dispatch/journey/routes.rb', line 10
def anchored_routes
@anchored_routes
end
|
#custom_routes ⇒ Object
Returns the value of attribute custom_routes
10
11
12
|
# File 'actionpack/lib/action_dispatch/journey/routes.rb', line 10
def custom_routes
@custom_routes
end
|
Returns the value of attribute routes
10
11
12
|
# File 'actionpack/lib/action_dispatch/journey/routes.rb', line 10
def routes
@routes
end
|
Instance Method Details
#add_route(name, mapping) ⇒ Object
65
66
67
68
69
70
71
|
# File 'actionpack/lib/action_dispatch/journey/routes.rb', line 65
def add_route(name, mapping)
route = mapping.make_route name, routes.length
routes << route
partition_route(route)
clear_cache!
route
end
|
51
52
53
54
55
56
|
# File 'actionpack/lib/action_dispatch/journey/routes.rb', line 51
def ast
@ast ||= begin
asts = anchored_routes.map(&:ast)
Nodes::Or.new(asts)
end
end
|
37
38
39
40
41
|
# File 'actionpack/lib/action_dispatch/journey/routes.rb', line 37
def clear
routes.clear
anchored_routes.clear
custom_routes.clear
end
|
#each(&block) ⇒ Object
33
34
35
|
# File 'actionpack/lib/action_dispatch/journey/routes.rb', line 33
def each(&block)
routes.each(&block)
end
|
#empty? ⇒ Boolean
20
21
22
|
# File 'actionpack/lib/action_dispatch/journey/routes.rb', line 20
def empty?
routes.empty?
end
|
29
30
31
|
# File 'actionpack/lib/action_dispatch/journey/routes.rb', line 29
def last
routes.last
end
|
#length ⇒ Object
Also known as:
size
24
25
26
|
# File 'actionpack/lib/action_dispatch/journey/routes.rb', line 24
def length
routes.length
end
|
#partition_route(route) ⇒ Object
43
44
45
46
47
48
49
|
# File 'actionpack/lib/action_dispatch/journey/routes.rb', line 43
def partition_route(route)
if route.path.anchored && route.ast.grep(Nodes::Symbol).all?(&:default_regexp?)
anchored_routes << route
else
custom_routes << route
end
end
|