Class: ActionController::Routing::RouteSet::NamedRouteCollection
- Inherits:
-
Object
- Object
- ActionController::Routing::RouteSet::NamedRouteCollection
show all
- Includes:
- Optimisation, Enumerable
- Defined in:
- lib/action_controller/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.
Constant Summary
Optimisation::OPTIMISERS
Instance Attribute Summary collapse
Instance Method Summary
collapse
#generate_optimisation_block
Constructor Details
Returns a new instance of NamedRouteCollection.
67
68
69
|
# File 'lib/action_controller/routing/route_set.rb', line 67
def initialize
clear!
end
|
Instance Attribute Details
Returns the value of attribute helpers.
65
66
67
|
# File 'lib/action_controller/routing/route_set.rb', line 65
def helpers
@helpers
end
|
Returns the value of attribute routes.
65
66
67
|
# File 'lib/action_controller/routing/route_set.rb', line 65
def routes
@routes
end
|
Instance Method Details
#add(name, route) ⇒ Object
Also known as:
[]=
81
82
83
84
|
# File 'lib/action_controller/routing/route_set.rb', line 81
def add(name, route)
routes[name.to_sym] = route
define_named_route_methods(name, route)
end
|
#clear! ⇒ Object
Also known as:
clear
71
72
73
74
75
76
77
78
79
|
# File 'lib/action_controller/routing/route_set.rb', line 71
def clear!
@routes = {}
@helpers = []
@module ||= Module.new
@module.instance_methods.each do |selector|
@module.class_eval { remove_method selector }
end
end
|
94
95
96
97
|
# File 'lib/action_controller/routing/route_set.rb', line 94
def each
routes.each { |name, route| yield name, route }
self
end
|
#get(name) ⇒ Object
Also known as:
[]
86
87
88
|
# File 'lib/action_controller/routing/route_set.rb', line 86
def get(name)
routes[name.to_sym]
end
|
#install(destinations = [ActionController::Base, ActionView::Base], regenerate = false) ⇒ Object
115
116
117
118
119
120
|
# File 'lib/action_controller/routing/route_set.rb', line 115
def install(destinations = [ActionController::Base, ActionView::Base], regenerate = false)
reset! if regenerate
Array(destinations).each do |dest|
dest.send! :include, @module
end
end
|
103
104
105
|
# File 'lib/action_controller/routing/route_set.rb', line 103
def length
routes.length
end
|
99
100
101
|
# File 'lib/action_controller/routing/route_set.rb', line 99
def names
routes.keys
end
|
107
108
109
110
111
112
113
|
# File 'lib/action_controller/routing/route_set.rb', line 107
def reset!
old_routes = routes.dup
clear!
old_routes.each do |name, route|
add(name, route)
end
end
|