Class: Rack::Throttle::UrlMatcher

Inherits:
Matcher
  • Object
show all
Defined in:
lib/rack/throttle/matchers/url_matcher.rb

Overview

UrlMatchers are used to restrict requests based on the URL requested. For instance, you may care about limiting requests to a machine-consumed API, but not be concerned about requests coming from browsers. UrlMatchers take Regexp object to match against the request path.

Instance Attribute Summary

Attributes inherited from Matcher

#rule

Instance Method Summary collapse

Methods inherited from Matcher

#initialize

Constructor Details

This class inherits a constructor from Rack::Throttle::Matcher

Instance Method Details

#identifierString

Returns:

  • (String)


18
19
20
# File 'lib/rack/throttle/matchers/url_matcher.rb', line 18

def identifier
  "url-" + @rule.inspect
end

#match?(request) ⇒ Boolean

Parameters:

  • request (Rack::Request)

Returns:

  • (Boolean)


12
13
14
# File 'lib/rack/throttle/matchers/url_matcher.rb', line 12

def match?(request)
  !!(@rule =~ request.path)
end