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, UnanchoredRegexp
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(ast, requirements, separators, anchored) ⇒ Pattern
Returns a new instance of Pattern.
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 9
def initialize(ast, requirements, separators, anchored)
@spec = ast
@requirements = requirements
@separators = separators
@anchored = anchored
@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
|
Instance Method Details
#ast ⇒ Object
33
34
35
36
37
38
39
40
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 33
def ast
@spec.find_all(&:symbol?).each do |node|
re = @requirements[node.to_sym]
node.regexp = re if re
end
@spec
end
|
22
23
24
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 22
def build_formatter
Visitors::FormatBuilder.new.accept(spec)
end
|
#eager_load! ⇒ Object
26
27
28
29
30
31
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 26
def eager_load!
required_names
offsets
to_regexp
nil
end
|
#match(other) ⇒ Object
Also known as:
=~
147
148
149
150
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 147
def match(other)
return unless match = to_regexp.match(other)
MatchData.new(names, offsets, match)
end
|
#match?(other) ⇒ Boolean
153
154
155
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 153
def match?(other)
to_regexp.match?(other)
end
|
#names ⇒ Object
42
43
44
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 42
def names
@names ||= spec.find_all(&:symbol?).map(&:name)
end
|
#optional_names ⇒ Object
50
51
52
53
54
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 50
def optional_names
@optional_names ||= spec.find_all(&:group?).flat_map { |group|
group.find_all(&:symbol?)
}.map(&:name).uniq
end
|
#required_names ⇒ Object
46
47
48
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 46
def required_names
@required_names ||= names - optional_names
end
|
#requirements_for_missing_keys_check ⇒ Object
165
166
167
168
169
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 165
def requirements_for_missing_keys_check
@requirements_for_missing_keys_check ||= requirements.transform_values do |regex|
/\A#{regex}\Z/
end
end
|
#source ⇒ Object
157
158
159
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 157
def source
to_regexp.source
end
|
#to_regexp ⇒ Object
161
162
163
|
# File 'lib/action_dispatch/journey/path/pattern.rb', line 161
def to_regexp
@re ||= regexp_visitor.new(@separators, @requirements).accept spec
end
|