From 86bcccf8dfced5e9428407a71f02c1dcc186f2ba Mon Sep 17 00:00:00 2001 From: thedarkone Date: Thu, 23 Sep 2010 18:08:43 +0200 Subject: [PATCH] No need to create a separate lambda for each call. --- .../lib/action_dispatch/routing/route_set.rb | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 1a5f21bd09..60b1342d55 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -334,6 +334,19 @@ module ActionDispatch end class Generator #:nodoc: + PARAMETERIZE = { + :parameterize => lambda do |name, value| + if name == :controller + value + elsif value.is_a?(Array) + value.map { |v| Rack::Mount::Utils.escape_uri(v.to_param) }.join('/') + else + return nil unless param = value.to_param + param.split('/').map { |v| Rack::Mount::Utils.escape_uri(v) }.join("/") + end + end + } + attr_reader :options, :recall, :set, :named_route def initialize(options, recall, set, extras = false) @@ -422,7 +435,7 @@ module ActionDispatch end def generate - path, params = @set.set.generate(:path_info, named_route, options, recall, opts) + path, params = @set.set.generate(:path_info, named_route, options, recall, PARAMETERIZE) raise_routing_error unless path @@ -436,20 +449,6 @@ module ActionDispatch raise_routing_error end - def opts - parameterize = lambda do |name, value| - if name == :controller - value - elsif value.is_a?(Array) - value.map { |v| Rack::Mount::Utils.escape_uri(v.to_param) }.join('/') - else - return nil unless param = value.to_param - param.split('/').map { |v| Rack::Mount::Utils.escape_uri(v) }.join("/") - end - end - {:parameterize => parameterize} - end - def raise_routing_error raise ActionController::RoutingError.new("No route matches #{options.inspect}") end