aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/routing/route_set.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-01-25 10:25:36 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2013-01-30 10:24:57 -0800
commit23b2d6069796ebf2e88261ad5667972d8b3f1e4d (patch)
tree852bdb19450c4ddf07bf08c600ecbecc1f01cb55 /actionpack/lib/action_dispatch/routing/route_set.rb
parent06f2ec4530ccf28a3da67b037b541d34ecef4658 (diff)
downloadrails-23b2d6069796ebf2e88261ad5667972d8b3f1e4d.tar.gz
rails-23b2d6069796ebf2e88261ad5667972d8b3f1e4d.tar.bz2
rails-23b2d6069796ebf2e88261ad5667972d8b3f1e4d.zip
move conditionals to instance
Diffstat (limited to 'actionpack/lib/action_dispatch/routing/route_set.rb')
-rw-r--r--actionpack/lib/action_dispatch/routing/route_set.rb22
1 files changed, 16 insertions, 6 deletions
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb
index 6c4315213c..3c9ad349e2 100644
--- a/actionpack/lib/action_dispatch/routing/route_set.rb
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb
@@ -182,6 +182,10 @@ module ActionDispatch
@route.requirements.except(:controller, :action).empty?
end
+ def arg_size
+ @route.required_parts.size
+ end
+
def optimized_helper
string_route = @route.ast.to_s
@@ -204,9 +208,17 @@ module ActionDispatch
end
def url_if(t, args)
- @options.merge!(t.url_options) if t.respond_to?(:url_options)
- @options[:path] = eval("\"#{optimized_helper}\"")
- ActionDispatch::Http::URL.url_for(@options)
+ if args.size == arg_size && !args.last.is_a?(Hash) && optimize_routes_generation?(t)
+ @options.merge!(t.url_options) if t.respond_to?(:url_options)
+ @options[:path] = eval("\"#{optimized_helper}\"")
+ ActionDispatch::Http::URL.url_for(@options)
+ else
+ url_else(t, args)
+ end
+ end
+
+ def optimize_routes_generation?(t)
+ t.send(:optimize_routes_generation?)
end
def handle_positional_args(t, args, options, segment_keys)
@@ -242,13 +254,11 @@ module ActionDispatch
helper = UrlHelper.create(route, options.dup)
ohelp = helper.optimize_helper?
- arg_size = route.required_parts.size
@module.module_eval do
define_method(name) do |*args|
#helper.call t, args
-
- if ohelp && args.size == arg_size && !args.last.is_a?(Hash) && optimize_routes_generation?
+ if ohelp
helper.url_if(self, args)
else
helper.url_else(self, args)