Class: ActionDispatch::Journey::Path::Pattern
Do not use. This class is for internal use only.
| Relationships & Source Files | |
| Namespace Children | |
|
Classes:
| |
| Inherits: | Object |
| Defined in: | actionpack/lib/action_dispatch/journey/path/pattern.rb |
Constant Summary
-
REGEXP_CACHE =
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 9{}
Class Method Summary
Instance Attribute Summary
- #anchored readonly
- #ast readonly
- #names readonly
- #requirements readonly
- #requirements_anchored? ⇒ Boolean readonly
- #spec readonly
Instance Method Summary
-
#=~(other)
Alias for #match.
- #build_formatter
- #eager_load!
- #match(other) (also: #=~)
- #match?(other) ⇒ Boolean
- #optional_names
- #required_names
- #requirements_for_missing_keys_check
- #source
- #to_regexp
- #offsets private
- #regexp_visitor private
Constructor Details
.new(ast, requirements, separators, anchored) ⇒ Pattern
# 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
Class Method Details
.dedup_regexp(regexp)
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 12
def dedup_regexp(regexp) REGEXP_CACHE[regexp.source] ||= regexp end
Instance Attribute Details
#anchored (readonly)
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 17
attr_reader :ast, :names, :requirements, :anchored, :spec
#ast (readonly)
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 17
attr_reader :ast, :names, :requirements, :anchored, :spec
#names (readonly)
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 17
attr_reader :ast, :names, :requirements, :anchored, :spec
#requirements (readonly)
[ GitHub ]
#requirements_anchored? ⇒ Boolean (readonly)
[ GitHub ]
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 44
def requirements_anchored? # each required param must not be surrounded by a literal, otherwise it isn't # simple to chunk-match the url piecemeal 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] # we also don't support this yet, constraints must be regexps return false if s.symbol? && s.regexp.is_a?(Array) return false if back.literal? return false if !fwd.nil? && fwd.literal? } true end
#spec (readonly)
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 17
attr_reader :ast, :names, :requirements, :anchored, :spec
Instance Method Details
#=~(other)
Alias for #match.
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 171
alias :=~ :match
#build_formatter
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 33
def build_formatter Visitors::FormatBuilder.new.accept(spec) end
#eager_load!
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 37
def eager_load! required_names offsets to_regexp @ast = nil end
#match(other) Also known as: #=~
[ GitHub ]
#match?(other) ⇒ Boolean
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 173
def match?(other) to_regexp.match?(other) end
#offsets (private)
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 196
def offsets @offsets ||= begin offsets = [0] spec.find_all(&:symbol?).each do |node| node = node.to_sym if @requirements.key?(node) re = Pattern.dedup_regexp(/#{Regexp.union(@requirements[node])}|/) offsets.push((re.match("").length - 1) + offsets.last) else offsets << offsets.last end end offsets end end
#optional_names
[ GitHub ]# 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
#regexp_visitor (private)
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 192
def regexp_visitor @anchored ? AnchoredRegexp : UnanchoredRegexp end
#required_names
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 66
def required_names @required_names ||= names - optional_names end
#requirements_for_missing_keys_check
[ GitHub ]# 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
#source
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 177
def source to_regexp.source end
#to_regexp
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 181
def to_regexp @re ||= regexp_visitor.new(@separators, @requirements).accept spec end