Sha256: 9bc5dfc11992be231d9f20e68f51eb60540f7ec12e5964aaafba8b71b1762ecb

Contents?: true

Size: 708 Bytes

Versions: 2

Compression:

Stored size: 708 Bytes

Contents

require 'active_support/core_ext/string/starts_ends_with'
require 'sparrow/path_normalizer'

module Sparrow
  class RouteParser
    include PathNormalizer

    attr_accessor :excluded_routes

    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

    def allow?(path)
      not exclude?(path)
    end

    def exclude?(path)
      normalized_path = normalize_path(path)
      excluded_routes.each do |route|
        return true if normalized_path =~ route
      end
      return false
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cp-sparrow-0.0.12 lib/sparrow/route_parser.rb
cp-sparrow-0.0.11 lib/sparrow/route_parser.rb