class ActionDispatch::Journey::Path::Pattern

Experimental RBS support (using type sampling data from the type_fusion project).

# sig/action_dispatch/journey/path/pattern.rbs

class ActionDispatch::Journey::Path::Pattern
  def match?: (String other) -> false
  def regexp_visitor: () -> Class
  def requirements_for_missing_keys_check: () -> Hash
  def to_regexp: () -> Regexp
end

:nodoc:
:nodoc:
:nodoc:

def build_formatter

def build_formatter
  Visitors::FormatBuilder.new.accept(spec)
end

def eager_load!

def eager_load!
  required_names
  offsets
  to_regexp
  @ast = nil
end

def initialize(ast, requirements, separators, anchored)

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

def match(other)

def match(other)
  return unless match = to_regexp.match(other)
  MatchData.new(names, offsets, match)
end

def match?(other)

Experimental RBS support (using type sampling data from the type_fusion project).

def match?: (String other) -> false

This signature was generated using 2 samples from 1 application.

def match?(other)
  to_regexp.match?(other)
end

def offsets

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

def optional_names

def optional_names
  @optional_names ||= spec.find_all(&:group?).flat_map { |group|
    group.find_all(&:symbol?)
  }.map(&:name).uniq
end

def regexp_visitor

Experimental RBS support (using type sampling data from the type_fusion project).

def regexp_visitor: () -> Class

This signature was generated using 1 sample from 1 application.

def regexp_visitor
  @anchored ? AnchoredRegexp : UnanchoredRegexp
end

def required_names

def required_names
  @required_names ||= names - optional_names
end

def requirements_anchored?

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

def requirements_for_missing_keys_check

Experimental RBS support (using type sampling data from the type_fusion project).

def requirements_for_missing_keys_check: () -> version | Regexp

This signature was generated using 5 samples from 1 application.

def requirements_for_missing_keys_check
  @requirements_for_missing_keys_check ||= requirements.transform_values do |regex|
    /\A#{regex}\Z/
  end
end

def source

def source
  to_regexp.source
end

def to_regexp

Experimental RBS support (using type sampling data from the type_fusion project).

def to_regexp: () -> Regexp

This signature was generated using 1 sample from 1 application.

def to_regexp
  @re ||= regexp_visitor.new(@separators, @requirements).accept spec
end