From 2cdbe2270d2072249cd1622d843645e2813535bd Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 25 Jan 2013 10:16:50 -0800 Subject: moving more stuff on to the instance --- .../lib/action_dispatch/routing/route_set.rb | 36 +++++++++++----------- 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 6c2f39afb3..4864475172 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -182,6 +182,23 @@ module ActionDispatch @route.requirements.except(:controller, :action).empty? end + def optimized_helper + string_route = @route.ast.to_s + + while string_route.gsub!(/\([^\)]*\)/, "") + true + end + + @route.required_parts.each_with_index do |part, i| + # Replace each route parameter + # e.g. :id for regular parameter or *path for globbing + # with ruby string interpolation code + string_route.gsub!(/(\*|:)#{part}/, "\#{Journey::Router::Utils.escape_fragment(args[#{i}].to_param)}") + end + + string_route + end + def url_else(t, args) t.url_for(handle_positional_args(t, args, @options, @segment_keys)) end @@ -225,7 +242,7 @@ module ActionDispatch helper = UrlHelper.create(route, options.dup) ohelp = helper.optimize_helper? - ohelper = optimized_helper(route) + ohelper = helper.optimized_helper arg_size = route.required_parts.size @module.module_eval do @@ -243,23 +260,6 @@ module ActionDispatch helpers << name end - # Generates the interpolation to be used in the optimized helper. - def optimized_helper(route) - string_route = route.ast.to_s - - while string_route.gsub!(/\([^\)]*\)/, "") - true - end - - route.required_parts.each_with_index do |part, i| - # Replace each route parameter - # e.g. :id for regular parameter or *path for globbing - # with ruby string interpolation code - string_route.gsub!(/(\*|:)#{part}/, "\#{Journey::Router::Utils.escape_fragment(args[#{i}].to_param)}") - end - - string_route - end end attr_accessor :formatter, :set, :named_routes, :default_scope, :router -- cgit v1.2.3