Class: ActionDispatch::Routing::RouteSet::NamedRouteCollection
- Inherits:
-
Object
- Object
- ActionDispatch::Routing::RouteSet::NamedRouteCollection
- Includes:
- Enumerable
- Defined in:
- 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
-
#helpers ⇒ Object
readonly
Returns the value of attribute helpers.
-
#module ⇒ Object
readonly
Returns the value of attribute module.
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
Instance Method Summary collapse
- #add(name, route) ⇒ Object (also: #[]=)
- #clear! ⇒ Object (also: #clear)
- #each ⇒ Object
- #get(name) ⇒ Object (also: #[])
- #helper_names ⇒ Object
-
#initialize ⇒ NamedRouteCollection
constructor
A new instance of NamedRouteCollection.
- #install(destinations = [ActionController::Base, ActionView::Base], regenerate = false) ⇒ Object
- #length ⇒ Object
- #names ⇒ Object
- #reset! ⇒ Object
Constructor Details
#initialize ⇒ NamedRouteCollection
Returns a new instance of NamedRouteCollection.
96 97 98 99 100 101 |
# File 'lib/action_dispatch/routing/route_set.rb', line 96 def initialize @routes = {} @helpers = [] @module = Module.new end |
Instance Attribute Details
#helpers ⇒ Object (readonly)
Returns the value of attribute helpers.
94 95 96 |
# File 'lib/action_dispatch/routing/route_set.rb', line 94 def helpers @helpers end |
#module ⇒ Object (readonly)
Returns the value of attribute module.
94 95 96 |
# File 'lib/action_dispatch/routing/route_set.rb', line 94 def module @module end |
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
94 95 96 |
# File 'lib/action_dispatch/routing/route_set.rb', line 94 def routes @routes end |
Instance Method Details
#add(name, route) ⇒ Object Also known as: []=
116 117 118 119 |
# File 'lib/action_dispatch/routing/route_set.rb', line 116 def add(name, route) routes[name.to_sym] = route define_named_route_methods(name, route) end |
#clear! ⇒ Object Also known as: clear
107 108 109 110 111 112 113 114 |
# File 'lib/action_dispatch/routing/route_set.rb', line 107 def clear! @helpers.each do |helper| @module.remove_possible_method helper end @routes.clear @helpers.clear end |
#each ⇒ Object
129 130 131 132 |
# File 'lib/action_dispatch/routing/route_set.rb', line 129 def each routes.each { |name, route| yield name, route } self end |
#get(name) ⇒ Object Also known as: []
121 122 123 |
# File 'lib/action_dispatch/routing/route_set.rb', line 121 def get(name) routes[name.to_sym] end |
#helper_names ⇒ Object
103 104 105 |
# File 'lib/action_dispatch/routing/route_set.rb', line 103 def helper_names self.module.instance_methods.map(&:to_s) end |
#install(destinations = [ActionController::Base, ActionView::Base], regenerate = false) ⇒ Object
150 151 152 153 154 155 |
# File 'lib/action_dispatch/routing/route_set.rb', line 150 def install(destinations = [ActionController::Base, ActionView::Base], regenerate = false) reset! if regenerate Array(destinations).each do |dest| dest.__send__(:include, @module) end end |
#length ⇒ Object
138 139 140 |
# File 'lib/action_dispatch/routing/route_set.rb', line 138 def length routes.length end |
#names ⇒ Object
134 135 136 |
# File 'lib/action_dispatch/routing/route_set.rb', line 134 def names routes.keys end |
#reset! ⇒ Object
142 143 144 145 146 147 148 |
# File 'lib/action_dispatch/routing/route_set.rb', line 142 def reset! old_routes = routes.dup clear! old_routes.each do |name, route| add(name, route) end end |