Class: ActionDispatch::Journey::Path::Pattern::RegexpOffsets

Inherits:
Visitors::Visitor show all
Defined in:
actionpack/lib/action_dispatch/journey/path/pattern.rb

Overview

:nodoc:

Constant Summary

Constants inherited from Visitors::Visitor

Visitors::Visitor::DISPATCH_CACHE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Visitors::Visitor

#accept

Constructor Details

#initialize(matchers) ⇒ RegexpOffsets

Returns a new instance of RegexpOffsets.



64
65
66
67
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 64

def initialize(matchers)
  @matchers      = matchers
  @capture_count = [0]
end

Instance Attribute Details

#offsetsObject (readonly)

Returns the value of attribute offsets



62
63
64
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 62

def offsets
  @offsets
end

Instance Method Details

#visit(node) ⇒ Object



69
70
71
72
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 69

def visit(node)
  super
  @capture_count
end

#visit_SYMBOL(node) ⇒ Object



74
75
76
77
78
79
80
81
82
83
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 74

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