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.
87
88
89
90
91
92
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 87
def initialize(separator, matchers)
@separator = separator
@matchers = matchers
@separator_re = "([^#{separator}]+)"
super()
end
|
Instance Method Details
#accept(node) ⇒ Object
94
95
96
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 94
def accept(node)
%r{\A#{visit node}\Z}
end
|
#visit_CAT(node) ⇒ Object
98
99
100
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 98
def visit_CAT(node)
[visit(node.left), visit(node.right)].join
end
|
#visit_GROUP(node) ⇒ Object
111
112
113
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 111
def visit_GROUP(node)
"(?:#{visit node.left})?"
end
|
#visit_LITERAL(node) ⇒ Object
Also known as:
visit_DOT
115
116
117
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 115
def visit_LITERAL(node)
Regexp.escape(node.left)
end
|
#visit_SLASH(node) ⇒ Object
120
121
122
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 120
def visit_SLASH(node)
node.left
end
|
#visit_STAR(node) ⇒ Object
124
125
126
127
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 124
def visit_STAR(node)
re = @matchers[node.left.to_sym] || '.+'
"(#{re})"
end
|
#visit_SYMBOL(node) ⇒ Object
102
103
104
105
106
107
108
109
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 102
def visit_SYMBOL(node)
node = node.to_sym
return @separator_re unless @matchers.key?(node)
re = @matchers[node]
"(#{re})"
end
|