Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

some refactoring of the match method

  • Loading branch information...
commit 76780c34f5e0f0e821e408482172454751514241 1 parent dda6787
@tenderlove tenderlove authored
Showing with 17 additions and 25 deletions.
  1. +17 −25 actionpack/lib/action_dispatch/routing/mapper.rb
View
42 actionpack/lib/action_dispatch/routing/mapper.rb
@@ -1245,32 +1245,38 @@ def shallow?
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 @@ def name_for_action(as, action) #:nodoc:
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 @@ def initialize(set) #:nodoc:
include Redirection
include Scoping
include Resources
- include Shorthand
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.