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
A new instance of NamedRouteCollection
81
82
83
|
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 81
def initialize
clear!
end
|
Instance Attribute Details
Returns the value of attribute helpers
79
80
81
|
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 79
def helpers
@helpers
end
|
Returns the value of attribute module
79
80
81
|
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 79
def module
@module
end
|
Returns the value of attribute routes
79
80
81
|
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 79
def routes
@routes
end
|
Instance Method Details
- (Object) add(name, route)
Also known as:
[]=
98
99
100
101
|
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 98
def add(name, route)
routes[name.to_sym] = route
define_named_route_methods(name, route)
end
|
- (Object) clear!
Also known as:
clear
89
90
91
92
93
94
95
96
|
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 89
def clear!
@routes = {}
@helpers = []
@module ||= Module.new do
instance_methods.each { |selector| remove_method(selector) }
end
end
|
111
112
113
114
|
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 111
def each
routes.each { |name, route| yield name, route }
self
end
|
- (Object) get(name)
Also known as:
[]
103
104
105
|
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 103
def get(name)
routes[name.to_sym]
end
|
- (Object) helper_names
85
86
87
|
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 85
def helper_names
self.module.instance_methods.map(&:to_s)
end
|
- (Object) install(destinations = [ActionController::Base, ActionView::Base], regenerate = false)
132
133
134
135
136
137
|
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 132
def install(destinations = [ActionController::Base, ActionView::Base], regenerate = false)
reset! if regenerate
Array(destinations).each do |dest|
dest.__send__(:include, @module)
end
end
|
120
121
122
|
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 120
def length
routes.length
end
|
116
117
118
|
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 116
def names
routes.keys
end
|
124
125
126
127
128
129
130
|
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 124
def reset!
old_routes = routes.dup
clear!
old_routes.each do |name, route|
add(name, route)
end
end
|