Class: ActionDispatch::Journey::Path::Pattern::AnchoredRegexp

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

Overview

:nodoc:

Direct Known Subclasses

UnanchoredRegexp

Constant Summary

Constants inherited from Visitors::Visitor

Visitors::Visitor::DISPATCH_CACHE

Instance Method Summary collapse

Constructor Details

#initialize(separator, matchers) ⇒ AnchoredRegexp

Returns a new instance of AnchoredRegexp.



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

def initialize(separator, matchers)
  @separator = separator
  @matchers  = matchers
  @separator_re = "([^#{separator}]+)"
  super()
end

Instance Method Details

#accept(node) ⇒ Object



76
77
78
# File 'lib/action_dispatch/journey/path/pattern.rb', line 76

def accept(node)
  %r{\A#{visit node}\Z}
end

#visit_CAT(node) ⇒ Object



80
81
82
# File 'lib/action_dispatch/journey/path/pattern.rb', line 80

def visit_CAT(node)
  "#{visit(node.left)}#{visit(node.right)}"
end

#visit_GROUP(node) ⇒ Object



93
94
95
# File 'lib/action_dispatch/journey/path/pattern.rb', line 93

def visit_GROUP(node)
  "(?:#{visit node.left})?"
end

#visit_LITERAL(node) ⇒ Object Also known as: visit_DOT



97
98
99
# File 'lib/action_dispatch/journey/path/pattern.rb', line 97

def visit_LITERAL(node)
  Regexp.escape(node.left)
end

#visit_OR(node) ⇒ Object



111
112
113
114
# File 'lib/action_dispatch/journey/path/pattern.rb', line 111

def visit_OR(node)
  children = node.children.map { |n| visit n }
  "(?:#{children.join(?|)})"
end

#visit_SLASH(node) ⇒ Object



102
103
104
# File 'lib/action_dispatch/journey/path/pattern.rb', line 102

def visit_SLASH(node)
  node.left
end

#visit_STAR(node) ⇒ Object



106
107
108
109
# File 'lib/action_dispatch/journey/path/pattern.rb', line 106

def visit_STAR(node)
  re = @matchers[node.left.to_sym]
  re ? "(#{re})" : "(.+)"
end

#visit_SYMBOL(node) ⇒ Object



84
85
86
87
88
89
90
91
# File 'lib/action_dispatch/journey/path/pattern.rb', line 84

def visit_SYMBOL(node)
  node = node.to_sym

  return @separator_re unless @matchers.key?(node)

  re = @matchers[node]
  "(#{Regexp.union(re)})"
end