Class: ActionDispatch::Routing::RouteSet::NamedRouteCollection::UrlHelper
- Defined in:
- actionpack/lib/action_dispatch/routing/route_set.rb
Direct Known Subclasses
Defined Under Namespace
Classes: OptimizedUrlHelper
Instance Attribute Summary collapse
-
#route_name ⇒ Object
readonly
Returns the value of attribute route_name.
Class Method Summary collapse
Instance Method Summary collapse
- #call(t, method_name, args, inner_options, url_strategy) ⇒ Object
- #handle_positional_args(controller_options, inner_options, args, result, path_params) ⇒ Object
-
#initialize(route, options, route_name) ⇒ UrlHelper
constructor
A new instance of UrlHelper.
Constructor Details
#initialize(route, options, route_name) ⇒ UrlHelper
Returns a new instance of UrlHelper.
255 256 257 258 259 260 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 255 def initialize(route, , route_name) @options = @segment_keys = route.segment_keys.uniq @route = route @route_name = route_name end |
Instance Attribute Details
#route_name ⇒ Object (readonly)
Returns the value of attribute route_name
185 186 187 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 185 def route_name @route_name end |
Class Method Details
.create(route, options, route_name) ⇒ Object
173 174 175 176 177 178 179 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 173 def self.create(route, , route_name) if optimize_helper?(route) OptimizedUrlHelper.new(route, , route_name) else new(route, , route_name) end end |
.optimize_helper?(route) ⇒ Boolean
181 182 183 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 181 def self.optimize_helper?(route) route.path.requirements.empty? && !route.glob? end |
Instance Method Details
#call(t, method_name, args, inner_options, url_strategy) ⇒ Object
262 263 264 265 266 267 268 269 270 271 272 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 262 def call(t, method_name, args, , url_strategy) = t. = .merge @options hash = handle_positional_args(, || {}, args, , @segment_keys) t._routes.url_for(hash, route_name, url_strategy, method_name) end |
#handle_positional_args(controller_options, inner_options, args, result, path_params) ⇒ Object
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 274 def handle_positional_args(, , args, result, path_params) if args.size > 0 # take format into account if path_params.include?(:format) path_params_size = path_params.size - 1 else path_params_size = path_params.size end if args.size < path_params_size path_params -= .keys path_params -= result.keys else path_params = path_params.dup end .each_key do |key| path_params.delete(key) end args.each_with_index do |arg, index| param = path_params[index] result[param] = arg if param end end result.merge!() end |