Class: ActionDispatch::Routing::RouteSet::NamedRouteCollection
- 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.
Defined Under Namespace
Classes: UrlHelper
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.
- #length ⇒ Object
- #names ⇒ Object
Methods included from Enumerable
#as_json, #exclude?, #index_by, #many?, #sum
Constructor Details
#initialize ⇒ NamedRouteCollection
Returns a new instance of NamedRouteCollection.
105 106 107 108 109 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 105 def initialize @routes = {} @helpers = [] @module = Module.new end |
Instance Attribute Details
#helpers ⇒ Object (readonly)
Returns the value of attribute helpers
103 104 105 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 103 def helpers @helpers end |
#module ⇒ Object (readonly)
Returns the value of attribute module
103 104 105 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 103 def module @module end |
#routes ⇒ Object (readonly)
Returns the value of attribute routes
103 104 105 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 103 def routes @routes end |
Instance Method Details
#add(name, route) ⇒ Object Also known as: []=
124 125 126 127 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 124 def add(name, route) routes[name.to_sym] = route define_named_route_methods(name, route) end |
#clear! ⇒ Object Also known as: clear
115 116 117 118 119 120 121 122 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 115 def clear! @helpers.each do |helper| @module.remove_possible_method helper end @routes.clear @helpers.clear end |
#each ⇒ Object
137 138 139 140 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 137 def each routes.each { |name, route| yield name, route } self end |
#get(name) ⇒ Object Also known as: []
129 130 131 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 129 def get(name) routes[name.to_sym] end |
#helper_names ⇒ Object
111 112 113 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 111 def helper_names @helpers.map(&:to_s) end |
#length ⇒ Object
146 147 148 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 146 def length routes.length end |
#names ⇒ Object
142 143 144 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 142 def names routes.keys end |