class ActionDispatch::Routing::RouteSet::NamedRouteCollection::UrlHelper::OptimizedUrlHelper

def call(t, args, inner_options)

def call(t, args, inner_options)
  if args.size == arg_size && !inner_options && optimize_routes_generation?(t)
    options = t.url_options.merge @options
    options[:path] = optimized_helper(args)
    url_strategy.call options
  else
    super
  end
end

def initialize(route, options, route_name, url_strategy)

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

def optimize_routes_generation?(t)

def optimize_routes_generation?(t)
  t.send(:optimize_routes_generation?)
end

def optimized_helper(args)

def optimized_helper(args)
  params = parameterize_args(args) do
    raise_generation_error(args)
  end
  @route.format params
end

def parameterize_args(args)

def parameterize_args(args)
  params = {}
  @arg_size.times { |i|
    key = @required_parts[i]
    value = args[i].to_param
    yield key if value.nil? || value.empty?
    params[key] = value
  }
  params
end

def raise_generation_error(args)

def raise_generation_error(args)
  missing_keys = []
  params = parameterize_args(args) { |missing_key|
    missing_keys << missing_key
  }
  constraints = Hash[@route.requirements.merge(params).sort_by{|k,v| k.to_s}]
  message = "No route matches #{constraints.inspect}"
  message << " missing required keys: #{missing_keys.sort.inspect}"
  raise ActionController::UrlGenerationError, message
end