aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch
diff options
context:
space:
mode:
authorBogdan Gusiev <agresso@gmail.com>2012-04-24 13:17:18 +0300
committerBogdan Gusiev <agresso@gmail.com>2012-04-24 13:17:18 +0300
commit15c5060bb5f0cbb3533d4ec76260de64449d19fb (patch)
treeec8ad1be9a219b21fb672918227ec85802f04cd5 /actionpack/lib/action_dispatch
parent242f4d1ebadd0cff83c10270aecd56752b9befc5 (diff)
downloadrails-15c5060bb5f0cbb3533d4ec76260de64449d19fb.tar.gz
rails-15c5060bb5f0cbb3533d4ec76260de64449d19fb.tar.bz2
rails-15c5060bb5f0cbb3533d4ec76260de64449d19fb.zip
RouteSet: simplify routes helpers generation code
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r--actionpack/lib/action_dispatch/routing/route_set.rb34
1 files changed, 21 insertions, 13 deletions
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb
index 45075050eb..c048338d40 100644
--- a/actionpack/lib/action_dispatch/routing/route_set.rb
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb
@@ -135,24 +135,32 @@ module ActionDispatch
end
private
- def url_helper_name(name, kind = :url)
- :"#{name}_#{kind}"
+ def url_helper_name(name, only_path)
+ if only_path
+ :"#{name}_path"
+ else
+ :"#{name}_url"
+ end
end
- def hash_access_name(name, kind = :url)
- :"hash_for_#{name}_#{kind}"
+ def hash_access_name(name, only_path)
+ if only_path
+ :"hash_for_#{name}_path"
+ else
+ :"hash_for_#{name}_url"
+ end
end
def define_named_route_methods(name, route)
- {:url => {:only_path => false}, :path => {:only_path => true}}.each do |kind, opts|
- hash = route.defaults.merge(:use_route => name).merge(opts)
- define_hash_access route, name, kind, hash
- define_url_helper route, name, kind, hash
+ [true, false].each do |only_path|
+ hash = route.defaults.merge(:use_route => name, :only_path => only_path)
+ define_hash_access route, name, hash
+ define_url_helper route, name, hash
end
end
- def define_hash_access(route, name, kind, options)
- selector = hash_access_name(name, kind)
+ def define_hash_access(route, name, options)
+ selector = hash_access_name(name, options[:only_path])
@module.module_eval do
remove_possible_method selector
@@ -187,9 +195,9 @@ module ActionDispatch
#
# foo_url(bar, baz, bang, :sort_by => 'baz')
#
- def define_url_helper(route, name, kind, options)
- selector = url_helper_name(name, kind)
- hash_access_method = hash_access_name(name, kind)
+ def define_url_helper(route, name, options)
+ selector = url_helper_name(name, options[:only_path])
+ hash_access_method = hash_access_name(name, options[:only_path])
if optimize_helper?(route)
@module.module_eval <<-END_EVAL, __FILE__, __LINE__ + 1