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
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
21
|
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 9
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
7
8
9
|
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 7
def anchored
@anchored
end
|
Returns the value of attribute ast
7
8
9
|
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 7
def ast
@ast
end
|
Returns the value of attribute names
7
8
9
|
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 7
def names
@names
end
|
#requirements ⇒ Object
Returns the value of attribute requirements
7
8
9
|
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 7
def requirements
@requirements
end
|
Returns the value of attribute spec
7
8
9
|
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 7
def spec
@spec
end
|
Instance Method Details
23
24
25
|
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 23
def build_formatter
Visitors::FormatBuilder.new.accept(spec)
end
|
#eager_load! ⇒ Object
27
28
29
30
31
32
|
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 27
def eager_load!
required_names
offsets
to_regexp
@ast = nil
end
|
#match(other) ⇒ Object
Also known as:
=~
156
157
158
159
|
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 156
def match(other)
return unless match = to_regexp.match(other)
MatchData.new(names, offsets, match)
end
|
#match?(other) ⇒ Boolean
162
163
164
|
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 162
def match?(other)
to_regexp.match?(other)
end
|
#optional_names ⇒ Object
59
60
61
62
63
|
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 59
def optional_names
@optional_names ||= spec.find_all(&:group?).flat_map { |group|
group.find_all(&:symbol?)
}.map(&:name).uniq
end
|
#required_names ⇒ Object
55
56
57
|
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 55
def required_names
@required_names ||= names - optional_names
end
|
#requirements_anchored? ⇒ Boolean
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 34
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
174
175
176
177
178
|
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 174
def requirements_for_missing_keys_check
@requirements_for_missing_keys_check ||= requirements.transform_values do |regex|
/\A#{regex}\Z/
end
end
|
166
167
168
|
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 166
def source
to_regexp.source
end
|
#to_regexp ⇒ Object
170
171
172
|
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 170
def to_regexp
@re ||= regexp_visitor.new(@separators, @requirements).accept spec
end
|