class Sparrow::RouteParser

Simple class the takes a list of routes and provides check methods to determine if a path is excluded (ignored) or not, i.e. the path is within the list as defined on initialization.

Attributes

excluded_routes[RW]

Public Class Methods

new(excluded_routes = Sparrow.configuration.excluded_routes) click to toggle source

Create a new Routeparser. @param [Array<String, Regexp>] excluded_routes A list of routes (path)

that shall not be parsed.
Each route +must+ not start with a leading slash (/).
# File lib/sparrow/route_parser.rb, line 14
def initialize(excluded_routes = Sparrow.configuration.excluded_routes)
  self.excluded_routes = excluded_routes.map do |route|
    if route.is_a?(Regexp)
      route
    else
      Regexp.new(route.to_s)
    end
  end
end

Public Instance Methods

allow?(path) click to toggle source

States if the given path is not within the excluded_routes

@param [String] path the path to be checked @return [Boolean] path allowed @see exclude? @see excluded_routes

# File lib/sparrow/route_parser.rb, line 31
def allow?(path)
  !exclude?(path)
end
exclude?(path) click to toggle source

States if the given path is within the excluded_routes, i.e. it may be ignored when parsing.

@param [String] path the path to be checked @return [Boolean] is path excluded

# File lib/sparrow/route_parser.rb, line 41
def exclude?(path)
  normalized_path = normalize_path(path)
  excluded_routes.each do |route|
    return true if normalized_path =~ route
  end
  return false
end

Private Instance Methods

normalize_path(path) click to toggle source
# File lib/sparrow/route_parser.rb, line 50
def normalize_path(path)
  path[/./m] = '' if path.to_s.starts_with?('/')
  path
end