Class: AccessAllow::AbilitiesManager

Inherits:
Object
  • Object
show all
Defined in:
lib/access_allow/abilities_manager.rb

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ AbilitiesManager

Returns a new instance of AbilitiesManager.



5
6
7
# File 'lib/access_allow/abilities_manager.rb', line 5

def initialize(user)
  @user = user
end

Instance Method Details

#has?(ability_namespace, ability_name) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
# File 'lib/access_allow/abilities_manager.rb', line 9

def has?(ability_namespace, ability_name)
  namespace = namespaced_context(ability_namespace)
  namespace[ability_name]
end

#to_aObject



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/access_allow/abilities_manager.rb', line 14

def to_a
  @to_a ||=
    combined_role_and_user_assigned.flat_map do |namespace, abilities|
      abilities
        .to_a
        .each_with_object([]) do |config, arr|
          ability, permitted = config
          arr << [namespace, ability.to_sym] if permitted
        end
    end
end