Class: ActionDispatch::Journey::Path::Pattern
- Inherits:
-
Object
- Object
- ActionDispatch::Journey::Path::Pattern
show all
- Defined in:
- actionpack/lib/action_dispatch/journey/path/pattern.rb
Overview
Defined Under Namespace
Classes: AnchoredRegexp, MatchData, UnanchoredRegexp
Constant Summary
collapse
- REGEXP_CACHE =
{}
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(ast, requirements, separators, anchored) ⇒ Pattern
Returns a new instance of Pattern.
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 19
def initialize(ast, requirements, separators, anchored)
@ast = ast
@spec = ast.root
@requirements = requirements
@separators = separators
@anchored = anchored
@names = ast.names
@optional_names = nil
@required_names = nil
@re = nil
@offsets = nil
end
|
Instance Attribute Details
Returns the value of attribute anchored.
17
18
19
|
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 17
def anchored
@anchored
end
|
Returns the value of attribute ast.
17
18
19
|
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 17
def ast
@ast
end
|
Returns the value of attribute names.
17
18
19
|
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 17
def names
@names
end
|
#requirements ⇒ Object
Returns the value of attribute requirements.
17
18
19
|
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 17
def requirements
@requirements
end
|
Returns the value of attribute spec.
17
18
19
|
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 17
def spec
@spec
end
|
Class Method Details
.dedup_regexp(regexp) ⇒ Object
12
13
14
|
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 12
def dedup_regexp(regexp)
REGEXP_CACHE[regexp.source] ||= regexp
end
|
Instance Method Details
33
34
35
|
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 33
def build_formatter
Visitors::FormatBuilder.new.accept(spec)
end
|
#eager_load! ⇒ Object
37
38
39
40
41
42
|
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 37
def eager_load!
required_names
offsets
to_regexp
@ast = nil
end
|
#match(other) ⇒ Object
Also known as:
=~
167
168
169
170
|
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 167
def match(other)
return unless match = to_regexp.match(other)
MatchData.new(names, offsets, match)
end
|
#match?(other) ⇒ Boolean
173
174
175
|
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 173
def match?(other)
to_regexp.match?(other)
end
|
#optional_names ⇒ Object
70
71
72
73
74
|
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 70
def optional_names
@optional_names ||= spec.find_all(&:group?).flat_map { |group|
group.find_all(&:symbol?)
}.map(&:name).uniq
end
|
#required_names ⇒ Object
66
67
68
|
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 66
def required_names
@required_names ||= names - optional_names
end
|
#requirements_anchored? ⇒ Boolean
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 44
def requirements_anchored?
terminals = ast.terminals
terminals.each_with_index { |s, index|
next if index < 1
next if s.type == :DOT || s.type == :SLASH
back = terminals[index - 1]
fwd = terminals[index + 1]
return false if s.symbol? && s.regexp.is_a?(Array)
return false if back.literal?
return false if !fwd.nil? && fwd.literal?
}
true
end
|
#requirements_for_missing_keys_check ⇒ Object
185
186
187
188
189
|
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 185
def requirements_for_missing_keys_check
@requirements_for_missing_keys_check ||= requirements.transform_values do |regex|
Pattern.dedup_regexp(/\A#{regex}\Z/)
end
end
|
177
178
179
|
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 177
def source
to_regexp.source
end
|
#to_regexp ⇒ Object
181
182
183
|
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 181
def to_regexp
@re ||= regexp_visitor.new(@separators, @requirements).accept spec
end
|