Class: PansophyAuthenticator::Matcher

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

Instance Method Summary collapse

Constructor Details

#initialize(keys, application) ⇒ Matcher

Returns a new instance of Matcher.



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

def initialize(keys, application)
  @keys        = keys
  @application = application
end

Instance Method Details

#keyObject



17
18
19
20
# File 'lib/pansophy_authenticator/matcher.rb', line 17

def key
  fail Error, "#{@application} is not defined" unless valid_application?
  @keys.fetch(@application)
end

#valid?(given_key) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
# File 'lib/pansophy_authenticator/matcher.rb', line 12

def valid?(given_key)
  return false unless valid_application?
  given_key == key
end

#valid_application?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/pansophy_authenticator/matcher.rb', line 22

def valid_application?
  @keys.key?(@application)
end

#validate!(given_key) ⇒ Object



8
9
10
# File 'lib/pansophy_authenticator/matcher.rb', line 8

def validate!(given_key)
  fail Error, 'Invalid application or key' unless valid?(given_key)
end