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.
103 104 105 106 107 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 103 def initialize @routes = {} @helpers = [] @module = Module.new end |
Instance Attribute Details
#helpers ⇒ Object (readonly)
Returns the value of attribute helpers
101 102 103 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 101 def helpers @helpers end |
#module ⇒ Object (readonly)
Returns the value of attribute module
101 102 103 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 101 def module @module end |
#routes ⇒ Object (readonly)
Returns the value of attribute routes
101 102 103 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 101 def routes @routes end |
Instance Method Details
#add(name, route) ⇒ Object Also known as: []=
122 123 124 125 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 122 def add(name, route) routes[name.to_sym] = route define_named_route_methods(name, route) end |
#clear! ⇒ Object Also known as: clear
113 114 115 116 117 118 119 120 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 113 def clear! @helpers.each do |helper| @module.remove_possible_method helper end @routes.clear @helpers.clear end |
#each ⇒ Object
135 136 137 138 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 135 def each routes.each { |name, route| yield name, route } self end |
#get(name) ⇒ Object Also known as: []
127 128 129 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 127 def get(name) routes[name.to_sym] end |
#helper_names ⇒ Object
109 110 111 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 109 def helper_names @helpers.map(&:to_s) end |
#length ⇒ Object
144 145 146 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 144 def length routes.length end |
#names ⇒ Object
140 141 142 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 140 def names routes.keys end |