Class: Moku::Policy

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

Overview

The policy is responsible for deciding whether or not a user can perform an action.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(roles) ⇒ Policy

Returns a new instance of Policy.


16
17
18
# File 'lib/moku/policy.rb', line 16

def initialize(roles)
  @roles = roles
end

Class Method Details

.all_rolesObject


8
9
10
# File 'lib/moku/policy.rb', line 8

def self.all_roles
  IMPLIED_BY.keys
end

.for(roles) ⇒ Object


12
13
14
# File 'lib/moku/policy.rb', line 12

def self.for(roles)
  new(roles)
end

Instance Method Details

#authorized?(action) ⇒ Boolean

Returns:

  • (Boolean)

20
21
22
# File 'lib/moku/policy.rb', line 20

def authorized?(action)
  role?(ACTION_TO_ROLE.fetch(action, :none))
end