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

Methods included from Scoped

#role?, #role_records, #roles, #scope?

Instance Method Details

#actor_idString

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.

Returns:

  • (String)


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.

Returns:

  • (Boolean)


116
117
118
# File 'app/models/concerns/masks/actor.rb', line 116

def anonymous?
  false
end

#authenticate(password) ⇒ Boolean

Validates the given password.

Parameters:

  • password (String)

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


102
103
104
# File 'app/models/concerns/masks/actor.rb', line 102

def mask!
  raise NotImplementedError
end

#nicknameString

A nickname for the actor.

Returns:

  • (String)

Raises:

  • (NotImplementedError)


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.

Parameters:

  • password (String)

Returns:

  • (String)

Raises:

  • (NotImplementedError)


59
60
61
62
63
# File 'app/models/concerns/masks/actor.rb', line 59

def password=(password)
  raise NotImplementedError unless defined?(super)

  super
end

#scopesArray<String>

Returns a list of scopes granted to the actor.

Returns:

  • (Array<String>)

    An array of scopes (as strings)

Raises:

  • (NotImplementedError)


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.

Parameters:

Returns:

  • (String)

Raises:

  • (NotImplementedError)


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_keyString

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.

Returns:

  • (String)


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

#versionString

An internal version counter for the actor.

Session keys use this value so they automatically expire when it changes.

Returns:

  • (String)

Raises:

  • (NotImplementedError)


40
41
42
43
44
# File 'app/models/concerns/masks/actor.rb', line 40

def version
  raise NotImplementedError unless defined?(super)

  super
end