Module: Masks::Actor
- Includes:
- Scoped
- Included in:
- Masks::Actors::Anonymous, Masks::Actors::System, Rails::Actor
- Defined in:
- app/models/concerns/masks/actor.rb
Overview
An interface that all masked actors should adhere to.
Instance Method Summary collapse
-
#actor_id ⇒ String
A unique identifier for the actor.
-
#anonymous? ⇒ Boolean
Whether or not the actor is anonymous, e.g.
-
#authenticate(password) ⇒ Boolean
Validates the given password.
-
#backup? ⇒ Boolean
Whether or not to save the results of any masked sessions involving this actor.
-
#factor2? ⇒ Boolean
Whether or not the actor requires a second layer of authentication.
-
#mask! ⇒ Boolean
A callback that is invoked for masked sessions involving this actor.
-
#nickname ⇒ String
A nickname for the actor.
-
#password=(password) ⇒ String
Sets a password for the actor.
-
#scopes ⇒ Array<String>
Returns a list of scopes granted to the actor.
-
#session=(session) ⇒ String
Sets the current session on the actor.
-
#session_key ⇒ String
A session identifier for the actor.
-
#version ⇒ String
An internal version counter for the actor.
Methods included from Scoped
#role?, #role_records, #roles, #scope?
Instance Method Details
#actor_id ⇒ String
A unique identifier for the actor.
This value is used for internal references to actors, e.g. when they are stored in the rails session.
19 20 21 |
# File 'app/models/concerns/masks/actor.rb', line 19 def actor_id nickname end |
#anonymous? ⇒ Boolean
Whether or not the actor is anonymous, e.g. instantiated but un-identified.
116 117 118 |
# File 'app/models/concerns/masks/actor.rb', line 116 def anonymous? false end |
#authenticate(password) ⇒ Boolean
Validates the given password.
79 80 81 82 83 |
# File 'app/models/concerns/masks/actor.rb', line 79 def authenticate(password) raise NotImplementedError unless defined?(super) super end |
#backup? ⇒ Boolean
Whether or not to save the results of any masked sessions involving this actor.
Typically this is best controlled at the mask level, but there are some cases where it is useful to control at the actor-level. For example, the implementation for anonymous actors always returns ‘true` for this method, so that anonymous actors never end up in the rails session or other databases.
128 129 130 |
# File 'app/models/concerns/masks/actor.rb', line 128 def backup? !anonymous? end |
#factor2? ⇒ Boolean
Whether or not the actor requires a second layer of authentication.
109 110 111 |
# File 'app/models/concerns/masks/actor.rb', line 109 def factor2? false end |
#mask! ⇒ Boolean
A callback that is invoked for masked sessions involving this actor.
This method is only called when everything else—credentials, checks, and other mask rules—have passed. If this method returns a truthy value the session will pass, otherwise it will fail.
This is a great place to add final checks, validations, and onboarding data to the actor before saving it.
102 103 104 |
# File 'app/models/concerns/masks/actor.rb', line 102 def mask! raise NotImplementedError end |
#nickname ⇒ String
A nickname for the actor.
49 50 51 52 53 |
# File 'app/models/concerns/masks/actor.rb', line 49 def nickname raise NotImplementedError unless defined?(super) super end |
#password=(password) ⇒ String
Sets a password for the actor.
59 60 61 62 63 |
# File 'app/models/concerns/masks/actor.rb', line 59 def password=(password) raise NotImplementedError unless defined?(super) super end |
#scopes ⇒ Array<String>
Returns a list of scopes granted to the actor.
88 89 90 |
# File 'app/models/concerns/masks/actor.rb', line 88 def scopes raise NotImplementedError end |
#session=(session) ⇒ String
Sets the current session on the actor.
69 70 71 72 73 |
# File 'app/models/concerns/masks/actor.rb', line 69 def session=(session) raise NotImplementedError unless defined?(super) super end |
#session_key ⇒ String
A session identifier for the actor.
This value is used for internal references to actors, e.g. when they are stored in the rails session.
29 30 31 32 33 |
# File 'app/models/concerns/masks/actor.rb', line 29 def session_key Digest::MD5.hexdigest( [Masks.configuration.version, version, actor_id].join("-") ) end |
#version ⇒ String
An internal version counter for the actor.
Session keys use this value so they automatically expire when it changes.
40 41 42 43 44 |
# File 'app/models/concerns/masks/actor.rb', line 40 def version raise NotImplementedError unless defined?(super) super end |