class StrongRoutes::RouteMatcher

Public Class Methods

new(route) click to toggle source
Calls superclass method
# File lib/strong_routes/route_matcher.rb, line 3
def initialize(route)
  if route.is_a?(Regexp)
    super(route)
  else
    route = map_dynamic_segments(route)
    route = "/#{route}" unless route =~ /\A\//
    escaped_route = Regexp.escape(route)
    super(/\A#{route}/i)
  end
end

Private Instance Methods

map_dynamic_segments(route) click to toggle source

Replace dynamic segments in the route with wildcards (e.g. /:foo/users/:id becomes /./users/.)

# File lib/strong_routes/route_matcher.rb, line 19
def map_dynamic_segments(route)
  route.to_s.gsub(/:\w+/, '.*')
end