Module: Masks::Scoped

Included in:
Actor, Rails::Key, Rails::OpenID::AccessToken, Rails::OpenID::Client
Defined in:
app/models/concerns/masks/scoped.rb

Overview

A smaller interface that all scoped actors should adhere to.

Instance Method Summary collapse

Instance Method Details

#role?(record, **opts) ⇒ Boolean

Returns whether or not a role is available to the scoped actor.

Parameters:

  • record (String|Object)

    or type

  • opts (Hash)

    to use for additional filtering

Returns:

  • (Boolean)


41
42
43
# File 'app/models/concerns/masks/scoped.rb', line 41

def role?(record, **opts)
  roles(record, **opts).any?
end

#role_records(record_type, **opts) ⇒ Object

Similar to roles_for, except all records are returned instead of the role.

Parameters:

  • record_type (String|Object)

    record or type

  • opts (Hash)

    to use for additional filtering

Returns:

  • (Object)

    a list of records, duplicates removed



50
51
52
# File 'app/models/concerns/masks/scoped.rb', line 50

def role_records(record_type, **opts)
  roles(record_type, **opts).map(&:record).uniq
end

#roles(record, **opts) ⇒ Masks::Role

Returns a list of Masks::Role records for the scoped actor.

Parameters:

  • record (String|Object)

    or type

  • opts (Hash)

    to use for additional filtering

Returns:

Raises:

  • (NotImplementedError)


32
33
34
# File 'app/models/concerns/masks/scoped.rb', line 32

def roles(record, **opts)
  raise NotImplementedError
end

#scope?(scope) ⇒ Boolean

Returns whether or not a scope is available.

In practice this is similar to calling scopes.include?(scope), but implementations may provide faster implementations.

Parameters:

  • scope (String)

Returns:

  • (Boolean)


23
24
25
# File 'app/models/concerns/masks/scoped.rb', line 23

def scope?(scope)
  scopes.include?(scope.to_s)
end

#scopesArray<String>

Returns a list of scopes granted to the actor.

Returns:

  • (Array<String>)

    An array of scopes (as strings)

Raises:

  • (NotImplementedError)


12
13
14
# File 'app/models/concerns/masks/scoped.rb', line 12

def scopes
  raise NotImplementedError
end