class Workarea::BasicAuth::Path

Attributes

regexp[R]

Public Class Methods

new(string, *http_methods) click to toggle source
# File lib/workarea/basic_auth/path.rb, line 6
def initialize(string, *http_methods)
  path = Regexp.escape(string).gsub('\*', ".*?")
  @regexp = Regexp.new("^#{path}$", true)

  if http_methods && http_methods.first.is_a?(Proc)
    @proc = http_methods.first
  end

  @http_methods = http_methods
end

Public Instance Methods

matches?(request) click to toggle source
# File lib/workarea/basic_auth/path.rb, line 17
def matches?(request)
  path_matches?(request) && request_matches?(request)
end

Private Instance Methods

path_matches?(request) click to toggle source
# File lib/workarea/basic_auth/path.rb, line 23
def path_matches?(request)
  !@regexp.match(request.path_info).nil?
end
request_matches?(request) click to toggle source
# File lib/workarea/basic_auth/path.rb, line 27
def request_matches?(request)
  if @proc
    @proc.call(request)
  else
    method = request.env["REQUEST_METHOD"].downcase.to_sym
    @http_methods.empty? || @http_methods.include?(method)
  end
end