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.
72
73
74
75
76
77
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 72
def initialize(separator, matchers)
@separator = separator
@matchers = matchers
@separator_re = "([^#{separator}]+)"
super()
end
|
Instance Method Details
#accept(node) ⇒ Object
79
80
81
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 79
def accept(node)
%r{\A#{visit node}\Z}
end
|
#visit_CAT(node) ⇒ Object
83
84
85
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 83
def visit_CAT(node)
[visit(node.left), visit(node.right)].join
end
|
#visit_GROUP(node) ⇒ Object
96
97
98
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 96
def visit_GROUP(node)
"(?:#{visit node.left})?"
end
|
#visit_LITERAL(node) ⇒ Object
Also known as:
visit_DOT
100
101
102
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 100
def visit_LITERAL(node)
Regexp.escape(node.left)
end
|
#visit_OR(node) ⇒ Object
114
115
116
117
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 114
def visit_OR(node)
children = node.children.map { |n| visit n }
"(?:#{children.join(?|)})"
end
|
#visit_SLASH(node) ⇒ Object
105
106
107
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 105
def visit_SLASH(node)
node.left
end
|
#visit_STAR(node) ⇒ Object
109
110
111
112
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 109
def visit_STAR(node)
re = @matchers[node.left.to_sym] || ".+"
"(#{re})"
end
|
#visit_SYMBOL(node) ⇒ Object
87
88
89
90
91
92
93
94
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 87
def visit_SYMBOL(node)
node = node.to_sym
return @separator_re unless @matchers.key?(node)
re = @matchers[node]
"(#{re})"
end
|