From 0127f02826fec6641c21779c4109a1d2ccb700fe Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 13 Aug 2014 19:13:58 -0700 Subject: only look up scope level once avoid hash lookups and remove depency on the instance --- actionpack/lib/action_dispatch/routing/mapper.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'actionpack/lib/action_dispatch') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 37f781a7dd..2f03e22be3 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -1726,20 +1726,21 @@ module ActionDispatch path || @scope[:path_names][name] || name.to_s end - def prefix_name_for_action(as, action) #:nodoc: + def prefix_name_for_action(as, action, scope_level) #:nodoc: if as prefix = as - elsif !canonical_action?(action, @scope[:scope_level]) + elsif !canonical_action?(action, scope_level) prefix = action end - if prefix + if prefix && prefix != '/' && !prefix.empty? Mapper.normalize_name prefix.to_s.tr('-', '_') end end def name_for_action(as, action) #:nodoc: - prefix = prefix_name_for_action(as, action) + scope_level = @scope[:scope_level] + prefix = prefix_name_for_action(as, action, scope_level) name_prefix = @scope[:as] if parent_resource @@ -1749,7 +1750,7 @@ module ActionDispatch member_name = parent_resource.member_name end - name = case @scope[:scope_level] + name = case scope_level when :nested [name_prefix, prefix] when :collection @@ -1764,7 +1765,7 @@ module ActionDispatch [name_prefix, member_name, prefix] end - if candidate = name.select(&:present?).join("_").presence + if candidate = name.compact.join("_").presence # If a name was not explicitly given, we check if it is valid # and return nil in case it isn't. Otherwise, we pass the invalid name # forward so the underlying router engine treats it and raises an exception. -- cgit v1.2.3