aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-10-21 10:25:47 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2011-11-18 10:51:09 -0800
commit76780c34f5e0f0e821e408482172454751514241 (patch)
tree47175603fc3c44c90e6fe4aa5e0106d6cb3bd528
parentdda6787f44a4e9a90cc28b3efee5b63c7d8cd023 (diff)
downloadrails-76780c34f5e0f0e821e408482172454751514241.tar.gz
rails-76780c34f5e0f0e821e408482172454751514241.tar.bz2
rails-76780c34f5e0f0e821e408482172454751514241.zip
some refactoring of the match method
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb42
1 files changed, 17 insertions, 25 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index 970236a05a..ff96b43a9d 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -1245,32 +1245,38 @@ module ActionDispatch
parent_resource.instance_of?(Resource) && @scope[:shallow]
end
- def match(*args)
- options = args.extract_options!.dup
+ def match(path, *rest)
+ if rest.empty? && Hash === path
+ options = path
+ path, to = options.find { |name, value| name.is_a?(String) }
+ options.merge!(:to => to).delete(path)
+ paths = [path]
+ else
+ options = rest.pop || {}
+ paths = [path] + rest
+ end
+
options[:anchor] = true unless options.key?(:anchor)
- if args.length > 1
- args.each { |path| match(path, options.dup) }
+ if paths.length > 1
+ paths.each { |path| match(path, options.dup) }
return self
end
on = options.delete(:on)
if VALID_ON_OPTIONS.include?(on)
- args.push(options)
- return send(on){ match(*args) }
+ return send(on){ match(path, options) }
elsif on
raise ArgumentError, "Unknown scope #{on.inspect} given to :on"
end
if @scope[:scope_level] == :resources
- args.push(options)
- return nested { match(*args) }
+ return nested { match(path, options) }
elsif @scope[:scope_level] == :resource
- args.push(options)
- return member { match(*args) }
+ return member { match(path, options) }
end
- action = args.first
+ action = path
path = path_for_action(action, options.delete(:path))
if action.to_s =~ /^[\w\/]+$/
@@ -1466,19 +1472,6 @@ module ActionDispatch
end
end
- module Shorthand #:nodoc:
- def match(path, *rest)
- if rest.empty? && Hash === path
- options = path
- path, to = options.find { |name, value| name.is_a?(String) }
- options.merge!(:to => to).delete(path)
- super(path, options)
- else
- super
- end
- end
- end
-
def initialize(set) #:nodoc:
@set = set
@scope = { :path_names => @set.resources_path_names }
@@ -1489,7 +1482,6 @@ module ActionDispatch
include Redirection
include Scoping
include Resources
- include Shorthand
end
end
end