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.
69
70
71
|
# File 'lib/action_controller/routing/route_set.rb', line 69
def initialize
clear!
end
|
Instance Attribute Details
Returns the value of attribute helpers.
67
68
69
|
# File 'lib/action_controller/routing/route_set.rb', line 67
def helpers
@helpers
end
|
Returns the value of attribute routes.
67
68
69
|
# File 'lib/action_controller/routing/route_set.rb', line 67
def routes
@routes
end
|
Instance Method Details
#add(name, route) ⇒ Object
Also known as:
[]=
83
84
85
86
|
# File 'lib/action_controller/routing/route_set.rb', line 83
def add(name, route)
routes[name.to_sym] = route
define_named_route_methods(name, route)
end
|
#clear! ⇒ Object
Also known as:
clear
73
74
75
76
77
78
79
80
81
|
# File 'lib/action_controller/routing/route_set.rb', line 73
def clear!
@routes = {}
@helpers = []
@module ||= Module.new
@module.instance_methods.each do |selector|
@module.class_eval { remove_method selector }
end
end
|
96
97
98
99
|
# File 'lib/action_controller/routing/route_set.rb', line 96
def each
routes.each { |name, route| yield name, route }
self
end
|
#get(name) ⇒ Object
Also known as:
[]
88
89
90
|
# File 'lib/action_controller/routing/route_set.rb', line 88
def get(name)
routes[name.to_sym]
end
|
#install(destinations = [ActionController::Base, ActionView::Base], regenerate = false) ⇒ Object
117
118
119
120
121
122
|
# File 'lib/action_controller/routing/route_set.rb', line 117
def install(destinations = [ActionController::Base, ActionView::Base], regenerate = false)
reset! if regenerate
Array(destinations).each do |dest|
dest.__send__(:include, @module)
end
end
|
105
106
107
|
# File 'lib/action_controller/routing/route_set.rb', line 105
def length
routes.length
end
|
101
102
103
|
# File 'lib/action_controller/routing/route_set.rb', line 101
def names
routes.keys
end
|
109
110
111
112
113
114
115
|
# File 'lib/action_controller/routing/route_set.rb', line 109
def reset!
old_routes = routes.dup
clear!
old_routes.each do |name, route|
add(name, route)
end
end
|