class Wayfarer::Routing::PathRule

@private

Attributes

matcher[R]

Public Class Methods

new(arg, opts = {}, &proc) click to toggle source
Calls superclass method
# File lib/wayfarer/routing/path_rule.rb, line 11
def initialize(arg, opts = {}, &proc)
  @matcher = if arg.is_a? String
               Mustermann.new(arg, type: Wayfarer.config.mustermann_type)
             else
               arg
             end

  super(opts, &proc)
end

Public Instance Methods

params(uri) click to toggle source
# File lib/wayfarer/routing/path_rule.rb, line 21
def params(uri)
  return {} unless match!(uri)

  path = uri.path

  if @matcher.is_a? Mustermann
    @matcher.params(path)
  else
    captures = @matcher.match(full_path(uri)).captures

    captures.each.with_index.reduce({}) do |hash, (capture, i)|
      hash.merge(i.to_s => capture)
    end
  end
end

Private Instance Methods

full_path(uri) click to toggle source

rubocop:enable Style/CaseEquality

# File lib/wayfarer/routing/path_rule.rb, line 49
def full_path(uri)
  "#{uri.path}?#{uri.query}##{uri.fragment}"
end
match!(uri) click to toggle source

rubocop:disable Style/CaseEquality

# File lib/wayfarer/routing/path_rule.rb, line 40
def match!(uri)
  if @matcher.is_a? Mustermann
    @matcher === uri.path
  else
    @matcher =~ full_path(uri)
  end
end