Class: ActionDispatch::Routing::RouteSet::NamedRouteCollection::UrlHelper::OptimizedUrlHelper

Inherits:
ActionDispatch::Routing::RouteSet::NamedRouteCollection::UrlHelper show all
Defined in:
actionpack/lib/action_dispatch/routing/route_set.rb

Instance Attribute Summary collapse

Attributes inherited from ActionDispatch::Routing::RouteSet::NamedRouteCollection::UrlHelper

#route_name

Instance Method Summary collapse

Methods inherited from ActionDispatch::Routing::RouteSet::NamedRouteCollection::UrlHelper

create, #handle_positional_args, optimize_helper?

Constructor Details

#initialize(route, options, route_name) ⇒ OptimizedUrlHelper

Returns a new instance of OptimizedUrlHelper.


190
191
192
193
194
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 190

def initialize(route, options, route_name)
  super
  @required_parts = @route.required_parts
  @arg_size       = @required_parts.size
end

Instance Attribute Details

#arg_sizeObject (readonly)

Returns the value of attribute arg_size.


188
189
190
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 188

def arg_size
  @arg_size
end

Instance Method Details

#call(t, method_name, args, inner_options, url_strategy) ⇒ Object


196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 196

def call(t, method_name, args, inner_options, url_strategy)
  if args.size == arg_size && !inner_options && optimize_routes_generation?(t)
    options = t.url_options.merge @options
    path = optimized_helper(args)
    path << "/" if options[:trailing_slash] && !path.end_with?("/")
    options[:path] = path

    original_script_name = options.delete(:original_script_name)
    script_name = t._routes.find_script_name(options)

    if original_script_name
      script_name = original_script_name + script_name
    end

    options[:script_name] = script_name

    url_strategy.call options
  else
    super
  end
end