class ActionDispatch::Routing::RouteSet::NamedRouteCollection::UrlHelper::OptimizedUrlHelper
def call(t, method_name, args, inner_options, url_strategy)
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
def initialize(route, options, route_name)
def initialize(route, options, route_name) 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