Class: BasicAuth::Matcher

Inherits:
Object
  • Object
show all
Defined in:
lib/basic_auth/matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(path, options = {}) ⇒ Matcher



3
4
5
6
# File 'lib/basic_auth/matcher.rb', line 3

def initialize(path, options={})
  @path, @options = path, options
  @protect = options[:protect]
end

Instance Method Details

#match?Boolean



8
9
10
11
12
13
14
# File 'lib/basic_auth/matcher.rb', line 8

def match?
  return true unless @protect # defaults to protect all
  # If user accidentally sets a string, change to a regexp
  pattern = @protect.is_a?(String) ? Regexp.new(@protect) : @protect
  matched = @path =~ pattern
  !!matched
end