Class: ActionDispatch::Journey::Path::Pattern::AnchoredRegexp
Overview
Constant Summary
Visitors::Visitor::DISPATCH_CACHE
Instance Method Summary
collapse
Constructor Details
#initialize(separator, matchers) ⇒ AnchoredRegexp
Returns a new instance of AnchoredRegexp.
66
67
68
69
70
71
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 66
def initialize(separator, matchers)
@separator = separator
@matchers = matchers
@separator_re = "([^#{separator}]+)"
super()
end
|
Instance Method Details
#accept(node) ⇒ Object
73
74
75
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 73
def accept(node)
%r{\A#{visit node}\Z}
end
|
#visit_CAT(node) ⇒ Object
77
78
79
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 77
def visit_CAT(node)
"#{visit(node.left)}#{visit(node.right)}"
end
|
#visit_GROUP(node) ⇒ Object
90
91
92
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 90
def visit_GROUP(node)
"(?:#{visit node.left})?"
end
|
#visit_LITERAL(node) ⇒ Object
Also known as:
visit_DOT
94
95
96
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 94
def visit_LITERAL(node)
Regexp.escape(node.left)
end
|
#visit_OR(node) ⇒ Object
108
109
110
111
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 108
def visit_OR(node)
children = node.children.map { |n| visit n }
"(?:#{children.join(?|)})"
end
|
#visit_SLASH(node) ⇒ Object
99
100
101
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 99
def visit_SLASH(node)
node.left
end
|
#visit_STAR(node) ⇒ Object
103
104
105
106
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 103
def visit_STAR(node)
re = @matchers[node.left.to_sym]
re ? "(#{re})" : "(.+)"
end
|
#visit_SYMBOL(node) ⇒ Object
81
82
83
84
85
86
87
88
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 81
def visit_SYMBOL(node)
node = node.to_sym
return @separator_re unless @matchers.key?(node)
re = @matchers[node]
"(#{Regexp.union(re)})"
end
|