Class: ActionDispatch::Routing::RouteSet::NamedRouteCollection::UrlHelper
- Inherits:
-
Object
- Object
- ActionDispatch::Routing::RouteSet::NamedRouteCollection::UrlHelper
show all
- Defined in:
- lib/action_dispatch/routing/route_set.rb
Defined Under Namespace
Classes: OptimizedUrlHelper
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(route, options, route_name, url_strategy) ⇒ UrlHelper
219
220
221
222
223
224
225
|
# File 'lib/action_dispatch/routing/route_set.rb', line 219
def initialize(route, options, route_name, url_strategy)
@options = options
@segment_keys = route.segment_keys.uniq
@route = route
@url_strategy = url_strategy
@route_name = route_name
end
|
Instance Attribute Details
#route_name ⇒ Object
Returns the value of attribute route_name.
160
161
162
|
# File 'lib/action_dispatch/routing/route_set.rb', line 160
def route_name
@route_name
end
|
#url_strategy ⇒ Object
Returns the value of attribute url_strategy.
160
161
162
|
# File 'lib/action_dispatch/routing/route_set.rb', line 160
def url_strategy
@url_strategy
end
|
Class Method Details
.create(route, options, route_name, url_strategy) ⇒ Object
148
149
150
151
152
153
154
|
# File 'lib/action_dispatch/routing/route_set.rb', line 148
def self.create(route, options, route_name, url_strategy)
if optimize_helper?(route)
OptimizedUrlHelper.new(route, options, route_name, url_strategy)
else
new route, options, route_name, url_strategy
end
end
|
.optimize_helper?(route) ⇒ Boolean
156
157
158
|
# File 'lib/action_dispatch/routing/route_set.rb', line 156
def self.optimize_helper?(route)
!route.glob? && route.path.requirements.empty?
end
|
Instance Method Details
#call(t, args, inner_options) ⇒ Object
227
228
229
230
231
232
233
234
235
236
237
|
# File 'lib/action_dispatch/routing/route_set.rb', line 227
def call(t, args, inner_options)
controller_options = t.url_options
options = controller_options.merge @options
hash = handle_positional_args(controller_options,
inner_options || {},
args,
options,
@segment_keys)
t._routes.url_for(hash, route_name, url_strategy)
end
|
#handle_positional_args(controller_options, inner_options, args, result, path_params) ⇒ Object
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
|
# File 'lib/action_dispatch/routing/route_set.rb', line 239
def handle_positional_args(controller_options, inner_options, args, result, path_params)
if args.size > 0
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 -= controller_options.keys
path_params -= result.keys
else
path_params = path_params.dup
end
inner_options.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!(inner_options)
end
|