aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2015-08-17 15:10:39 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2015-08-17 15:11:20 -0700
commit56f734a3615ad522a1dbaafc7442f19e4651640b (patch)
treed9f64095652ee71486911867beee2ae65a1756e7
parent15bc6b630f8ac3c57f12b8108e4842c603e86a84 (diff)
downloadrails-56f734a3615ad522a1dbaafc7442f19e4651640b.tar.gz
rails-56f734a3615ad522a1dbaafc7442f19e4651640b.tar.bz2
rails-56f734a3615ad522a1dbaafc7442f19e4651640b.zip
pull RegexpOffsets in to a method
we don't really need this visitor
-rw-r--r--actionpack/lib/action_dispatch/journey/path/pattern.rb41
1 files changed, 14 insertions, 27 deletions
diff --git a/actionpack/lib/action_dispatch/journey/path/pattern.rb b/actionpack/lib/action_dispatch/journey/path/pattern.rb
index cb1a65e1f4..2b384149f9 100644
--- a/actionpack/lib/action_dispatch/journey/path/pattern.rb
+++ b/actionpack/lib/action_dispatch/journey/path/pattern.rb
@@ -59,31 +59,6 @@ module ActionDispatch
}.map(&:name).uniq
end
- class RegexpOffsets < Journey::Visitors::Visitor # :nodoc:
- attr_reader :offsets
-
- def initialize(matchers)
- @matchers = matchers
- @capture_count = [0]
- end
-
- def visit(node)
- super
- @capture_count
- end
-
- def visit_SYMBOL(node)
- node = node.to_sym
-
- if @matchers.key?(node)
- re = /#{@matchers[node]}|/
- @capture_count.push((re.match('').length - 1) + (@capture_count.last || 0))
- else
- @capture_count << (@capture_count.last || 0)
- end
- end
- end
-
class AnchoredRegexp < Journey::Visitors::Visitor # :nodoc:
def initialize(separator, matchers)
@separator = separator
@@ -193,8 +168,20 @@ module ActionDispatch
def offsets
return @offsets if @offsets
- viz = RegexpOffsets.new(@requirements)
- @offsets = viz.accept(spec)
+ @offsets = [0]
+
+ spec.find_all(&:symbol?).each do |node|
+ node = node.to_sym
+
+ if @requirements.key?(node)
+ re = /#{@requirements[node]}|/
+ @offsets.push((re.match('').length - 1) + @offsets.last)
+ else
+ @offsets << @offsets.last
+ end
+ end
+
+ @offsets
end
end
end