module Beryl::Routing::Matcher

Constants

DEFAULT_CONSTRAINT

Public Instance Methods

match(route, path) click to toggle source
# File lib/beryl/routing/matcher.rb, line 8
def match(route, path)
  params = params(route)
  r = params.each_with_object("#{route.clone}") do |param, result|
    result.sub!(":#{param}", "(#{DEFAULT_CONSTRAINT})")
  end
  regex = /\A#{r}\z/
  matched = regex.match(path)
  return false unless matched
  params(route).each_with_object({}).with_index do |(param, result), index|
    result[param] = matched[index + 1]
  end

end

Private Instance Methods

params(route) click to toggle source
# File lib/beryl/routing/matcher.rb, line 24
def params(route)
  route.scan(/:[[:lower:]_]+[[:lower:][:digit:]_]*/).map { |param| param[1..-1].to_sym }
end