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


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

def initialize(route, options)
  super
  @path_parts   = @route.required_parts
  @arg_size     = @path_parts.size
  @string_route = @route.optimized_path
end

Instance Attribute Details

#arg_sizeObject (readonly)

Returns the value of attribute arg_size


162
163
164
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 162

def arg_size
  @arg_size
end

Instance Method Details

#call(t, args) ⇒ Object


171
172
173
174
175
176
177
178
179
180
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 171

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