Class: ActionDispatch::Routing::RouteSet::NamedRouteCollection
- Inherits:
-
Object
- Object
- ActionDispatch::Routing::RouteSet::NamedRouteCollection
show all
- Includes:
- Enumerable
- Defined in:
- actionpack/lib/action_dispatch/routing/route_set.rb
Overview
A NamedRouteCollection instance is a collection of named routes, and also maintains an anonymous module that can be used to install helpers for the named routes.
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Enumerable
#as_json, #each_with_object, #exclude?, #group_by, #index_by, #many?, #sum
Constructor Details
Returns a new instance of NamedRouteCollection.
96
97
98
|
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 96
def initialize
clear!
end
|
Instance Attribute Details
Returns the value of attribute helpers
94
95
96
|
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 94
def helpers
@helpers
end
|
Returns the value of attribute module
94
95
96
|
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 94
def module
@module
end
|
Returns the value of attribute routes
94
95
96
|
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 94
def routes
@routes
end
|
Instance Method Details
#add(name, route) ⇒ Object
Also known as:
[]=
113
114
115
116
|
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 113
def add(name, route)
routes[name.to_sym] = route
define_named_route_methods(name, route)
end
|
#clear! ⇒ Object
Also known as:
clear
104
105
106
107
108
109
110
111
|
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 104
def clear!
@routes = {}
@helpers = []
@module ||= Module.new do
instance_methods.each { |selector| remove_method(selector) }
end
end
|
126
127
128
129
|
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 126
def each
routes.each { |name, route| yield name, route }
self
end
|
#get(name) ⇒ Object
Also known as:
[]
118
119
120
|
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 118
def get(name)
routes[name.to_sym]
end
|
#helper_names ⇒ Object
100
101
102
|
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 100
def helper_names
self.module.instance_methods.map(&:to_s)
end
|
#install(destinations = [ActionController::Base, ActionView::Base], regenerate = false) ⇒ Object
147
148
149
150
151
152
|
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 147
def install(destinations = [ActionController::Base, ActionView::Base], regenerate = false)
reset! if regenerate
Array(destinations).each do |dest|
dest.__send__(:include, @module)
end
end
|
135
136
137
|
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 135
def length
routes.length
end
|
131
132
133
|
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 131
def names
routes.keys
end
|
139
140
141
142
143
144
145
|
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 139
def reset!
old_routes = routes.dup
clear!
old_routes.each do |name, route|
add(name, route)
end
end
|