Class: Sparrow::RouteParser
- Inherits:
-
Object
- Object
- Sparrow::RouteParser
- Defined in:
- lib/sparrow/route_parser.rb
Overview
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.
Instance Attribute Summary collapse
-
#excluded_routes ⇒ Object
Returns the value of attribute excluded_routes.
Instance Method Summary collapse
-
#allow?(path) ⇒ Boolean
States if the given path is
not
within the excluded_routes. -
#exclude?(path) ⇒ Boolean
States if the given path is within the excluded_routes, i.e.
-
#initialize(excluded_routes = Sparrow.configuration.excluded_routes) ⇒ RouteParser
constructor
Create a new Routeparser.
Constructor Details
#initialize(excluded_routes = Sparrow.configuration.excluded_routes) ⇒ RouteParser
Create a new Routeparser.
14 15 16 17 18 19 20 21 22 |
# 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 |
Instance Attribute Details
#excluded_routes ⇒ Object
Returns the value of attribute excluded_routes.
7 8 9 |
# File 'lib/sparrow/route_parser.rb', line 7 def excluded_routes @excluded_routes end |
Instance Method Details
#allow?(path) ⇒ Boolean
States if the given path is not
within the excluded_routes
31 32 33 |
# File 'lib/sparrow/route_parser.rb', line 31 def allow?(path) !exclude?(path) end |
#exclude?(path) ⇒ Boolean
States if the given path is within the excluded_routes, i.e. it may be ignored when parsing.
41 42 43 44 45 46 47 |
# 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 |