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 |
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 11
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
#anchored (readonly)
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 9
attr_reader :ast, :names, :requirements, :anchored, :spec
#ast (readonly)
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 9
attr_reader :ast, :names, :requirements, :anchored, :spec
#names (readonly)
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 9
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 36
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 9
attr_reader :ast, :names, :requirements, :anchored, :spec
Instance Method Details
#=~(other)
Alias for #match.
# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 163
alias :=~ :match
#build_formatter
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 25
def build_formatter Visitors::FormatBuilder.new.accept(spec) end
#eager_load!
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 29
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 165
def match?(other) to_regexp.match?(other) end
#offsets (private)
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 188
def offsets @offsets ||= begin offsets = [0] spec.find_all(&:symbol?).each do |node| node = node.to_sym if @requirements.key?(node) re = /#{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 62
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 184
def regexp_visitor @anchored ? AnchoredRegexp : UnanchoredRegexp end
#required_names
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 58
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 177
def requirements_for_missing_keys_check @requirements_for_missing_keys_check ||= requirements.transform_values do |regex| /\A#{regex}\Z/ end end
#source
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 169
def source to_regexp.source end
#to_regexp
[ GitHub ]# File 'actionpack/lib/action_dispatch/journey/path/pattern.rb', line 173
def to_regexp @re ||= regexp_visitor.new(@separators, @requirements).accept spec end