Class: PansophyAuthenticator::Matcher
- Inherits:
-
Object
- Object
- PansophyAuthenticator::Matcher
- Defined in:
- lib/pansophy_authenticator/matcher.rb
Instance Method Summary collapse
-
#initialize(keys, application) ⇒ Matcher
constructor
A new instance of Matcher.
- #key ⇒ Object
- #valid?(given_key) ⇒ Boolean
- #valid_application? ⇒ Boolean
- #validate!(given_key) ⇒ Object
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
#key ⇒ Object
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
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
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 |