Skip to content

Commit

Permalink
move conditionals to instance
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Jan 30, 2013
1 parent 06f2ec4 commit 23b2d60
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions actionpack/lib/action_dispatch/routing/route_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ def optimize_helper?
@route.requirements.except(:controller, :action).empty?
end

def arg_size
@route.required_parts.size
end

def optimized_helper
string_route = @route.ast.to_s

Expand All @@ -204,9 +208,17 @@ def url_else(t, args)
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)
Expand Down Expand Up @@ -242,13 +254,11 @@ def define_url_helper(route, name, options)
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)
Expand Down

0 comments on commit 23b2d60

Please sign in to comment.