Class: Passwordless::Constraint
- Inherits:
-
Object
- Object
- Passwordless::Constraint
- Includes:
- ControllerHelpers
- Defined in:
- lib/passwordless/constraint.rb
Overview
A class the constraint routes to authenticated records
Direct Known Subclasses
Instance Attribute Summary collapse
-
#authenticatable_type ⇒ Object
readonly
Returns the value of attribute authenticatable_type.
-
#predicate ⇒ Object
readonly
Returns the value of attribute predicate.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
Instance Method Summary collapse
-
#initialize(authenticatable_type, **options) ⇒ Constraint
constructor
A new instance of Constraint.
- #matches?(request) ⇒ Boolean
Methods included from ControllerHelpers
#authenticate_by_session, #build_passwordless_session, #create_passwordless_session, #create_passwordless_session!, #find_passwordless_session_for, #redirect_session_key, #reset_passwordless_redirect_location!, #save_passwordless_redirect_location!, #session_key, #sign_in, #sign_out
Constructor Details
#initialize(authenticatable_type, **options) ⇒ Constraint
Returns a new instance of Constraint.
14 15 16 17 18 |
# File 'lib/passwordless/constraint.rb', line 14 def initialize(authenticatable_type, **) @authenticatable_type = authenticatable_type # `if' is a keyword but so we do this instead of keyword arguments @predicate = .fetch(:if) { -> (_) { true } } end |
Instance Attribute Details
#authenticatable_type ⇒ Object (readonly)
Returns the value of attribute authenticatable_type.
10 11 12 |
# File 'lib/passwordless/constraint.rb', line 10 def authenticatable_type @authenticatable_type end |
#predicate ⇒ Object (readonly)
Returns the value of attribute predicate.
10 11 12 |
# File 'lib/passwordless/constraint.rb', line 10 def predicate @predicate end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
10 11 12 |
# File 'lib/passwordless/constraint.rb', line 10 def session @session end |
Instance Method Details
#matches?(request) ⇒ Boolean
20 21 22 23 24 25 |
# File 'lib/passwordless/constraint.rb', line 20 def matches?(request) # used in authenticate_by_session @session = request.session authenticatable = authenticate_by_session(authenticatable_type) !!(authenticatable && predicate.call(authenticatable)) end |