Class: ActionDispatch::Journey::Path::Pattern
- Inherits:
-
Object
- Object
- ActionDispatch::Journey::Path::Pattern
show all
- Defined in:
- lib/action_dispatch/journey/path/pattern.rb
Overview
Defined Under Namespace
Classes: AnchoredRegexp, MatchData, RegexpOffsets, UnanchoredRegexp
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(strexp) ⇒ Pattern
Returns a new instance of Pattern.
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 13
def initialize(strexp)
@spec = strexp.ast
@requirements = strexp.requirements
@separators = strexp.separators.join
@anchored = strexp.anchor
@names = nil
@optional_names = nil
@required_names = nil
@re = nil
@offsets = nil
end
|
Instance Attribute Details
#anchored ⇒ Object
Returns the value of attribute anchored.
7
8
9
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 7
def anchored
@anchored
end
|
#requirements ⇒ Object
Returns the value of attribute requirements.
7
8
9
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 7
def requirements
@requirements
end
|
#spec ⇒ Object
Returns the value of attribute spec.
7
8
9
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 7
def spec
@spec
end
|
Class Method Details
.from_string(string) ⇒ Object
9
10
11
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 9
def self.from_string string
new Journey::Router::Strexp.build(string, {}, ["/.?"], true)
end
|
Instance Method Details
#ast ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 30
def ast
@spec.grep(Nodes::Symbol).each do |node|
re = @requirements[node.to_sym]
node.regexp = re if re
end
@spec.grep(Nodes::Star).each do |node|
node = node.left
node.regexp = @requirements[node.to_sym] || /(.+)/
end
@spec
end
|
26
27
28
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 26
def build_formatter
Visitors::FormatBuilder.new.accept(spec)
end
|
#match(other) ⇒ Object
Also known as:
=~
164
165
166
167
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 164
def match(other)
return unless match = to_regexp.match(other)
MatchData.new(names, offsets, match)
end
|
#names ⇒ Object
44
45
46
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 44
def names
@names ||= spec.grep(Nodes::Symbol).map { |n| n.name }
end
|
#optional_names ⇒ Object
52
53
54
55
56
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 52
def optional_names
@optional_names ||= spec.grep(Nodes::Group).flat_map { |group|
group.grep(Nodes::Symbol)
}.map { |n| n.name }.uniq
end
|
#required_names ⇒ Object
48
49
50
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 48
def required_names
@required_names ||= names - optional_names
end
|
#source ⇒ Object
170
171
172
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 170
def source
to_regexp.source
end
|
#to_regexp ⇒ Object
174
175
176
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 174
def to_regexp
@re ||= regexp_visitor.new(@separators, @requirements).accept spec
end
|