Skip to content

Commit

Permalink
RouteSet: remove some code dups
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan committed May 2, 2012
1 parent 02f2e3d commit da88d80
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions actionpack/lib/action_dispatch/routing/route_set.rb
Expand Up @@ -184,27 +184,18 @@ def define_named_route_methods(name, route)
def define_url_helper(route, name, options)
selector = url_helper_name(name, options[:only_path])

if optimize_helper?(route)
@module.module_eval <<-END_EVAL, __FILE__, __LINE__ + 1
remove_possible_method :#{selector}
def #{selector}(*args)
if args.size == #{route.required_parts.size} && !args.last.is_a?(Hash) && optimize_routes_generation?
options = #{options.inspect}.merge!(url_options)
options[:path] = "#{optimized_helper(route)}"
ActionDispatch::Http::URL.url_for(options)
else
url_for(handle_positional_args(args, #{options.inspect}, #{route.segment_keys.inspect}))
end
end
END_EVAL
else
@module.module_eval <<-END_EVAL, __FILE__, __LINE__ + 1
remove_possible_method :#{selector}
def #{selector}(*args)
@module.module_eval <<-END_EVAL, __FILE__, __LINE__ + 1
remove_possible_method :#{selector}
def #{selector}(*args)
if #{optimize_helper?(route)} && args.size == #{route.required_parts.size} && !args.last.is_a?(Hash) && optimize_routes_generation?
options = #{options.inspect}.merge!(url_options)
options[:path] = "#{optimized_helper(route)}"
ActionDispatch::Http::URL.url_for(options)
else
url_for(handle_positional_args(args, #{options.inspect}, #{route.segment_keys.inspect}))
end
END_EVAL
end
end
END_EVAL

helpers << selector
end
Expand Down

0 comments on commit da88d80

Please sign in to comment.