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

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

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

create, #handle_positional_args, optimize_helper?

Constructor Details

#initialize(route, options) ⇒ OptimizedUrlHelper

Returns a new instance of OptimizedUrlHelper.



166
167
168
169
170
171
172
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 166

def initialize(route, options)
  super
  @klass          = Journey::Router::Utils
  @required_parts = @route.required_parts
  @arg_size       = @required_parts.size
  @optimized_path = @route.optimized_path
end

Instance Attribute Details

#arg_sizeObject (readonly)

Returns the value of attribute arg_size



164
165
166
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 164

def arg_size
  @arg_size
end

Instance Method Details

#call(t, args) ⇒ Object



174
175
176
177
178
179
180
181
182
183
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 174

def call(t, args)
  if args.size == arg_size && !args.last.is_a?(Hash) && optimize_routes_generation?(t)
    options = @options.dup
    options.merge!(t.url_options) if t.respond_to?(:url_options)
    options[:path] = optimized_helper(args)
    ActionDispatch::Http::URL.url_for(options)
  else
    super
  end
end