Class: Moku::AuthService

Inherits:
Object
  • Object
show all
Defined in:
lib/moku/auth_service.rb

Overview

Authorizes activities from the loaded role information. It delegates to the policies generated by the inserted policy_factory.

Instance Method Summary collapse

Constructor Details

#initialize(global: {}, instances: {}, policy_factory: Policy) ⇒ AuthService

Returns a new instance of AuthService.


16
17
18
19
20
# File 'lib/moku/auth_service.rb', line 16

def initialize(global: {}, instances: {}, policy_factory: Policy)
  @global = global
  @instances = instances
  @policy_factory = policy_factory
end

Instance Method Details

#authorized?(user:, entity:, action:) ⇒ Boolean

Returns:

  • (Boolean)

22
23
24
25
26
# File 'lib/moku/auth_service.rb', line 22

def authorized?(user:, entity:, action:)
  return false unless user && entity && action

  policy(user, entity).authorized?(action)
end