Class: CanTango::AbilityExecutor

Inherits:
Ability
  • Object
show all
Defined in:
lib/cantango/ability_executor.rb

Instance Attribute Summary

Attributes inherited from Ability

#candidate, #options

Instance Method Summary collapse

Methods inherited from Ability

#cached?, #clear_rules!, #config, #permit_rules, #session, #subject

Methods included from CanTango::Ability::RoleHelpers

#role_groups, #roles

Methods included from Helpers::RoleMethods

#config, #has_role_group_meth, #has_role_meth, #role_groups_list_meth, #roles_list_meth

Methods included from CanTango::Ability::UserHelpers

#user, #user_account, #user_key_field

Methods included from CanTango::Ability::PermitHelpers

#permits?

Methods included from CanTango::Ability::MasqueradeHelpers

#masquerade_account?, #masquerade_user?, #masquerading?, #masquerading_off?

Methods included from CanTango::Ability::CacheHelpers

#cache

Methods included from CanTango::Ability::EngineHelpers

#each_engine, #engines, #engines_on?, #execute_engines!, #opts_engines_off?

Methods included from PermitEngine::Util

#localhost_manager?, #permit_name, #role

Constructor Details

#initialize(candidate, options = {}) ⇒ AbilityExecutor

Returns a new instance of AbilityExecutor.



4
5
6
7
8
9
10
# File 'lib/cantango/ability_executor.rb', line 4

def initialize candidate, options = {}
  raise "Candidate must be something!" if !candidate
  @candidate, @options = [candidate, options]
  @rules = cached_rules + non_cached_rules
  rules.flatten!
  rules.compact!
end

Instance Method Details

#cached_abilityObject



24
25
26
# File 'lib/cantango/ability_executor.rb', line 24

def cached_ability
  CanTango::CachedAbility.new candidate, options
end

#cached_rulesObject



16
17
18
# File 'lib/cantango/ability_executor.rb', line 16

def cached_rules
  cache_mode? ? cached_ability.send(:rules) : []
end

#non_cached_abilityObject



28
29
30
# File 'lib/cantango/ability_executor.rb', line 28

def non_cached_ability
  CanTango::Ability.new candidate, options
end

#non_cached_rulesObject



20
21
22
# File 'lib/cantango/ability_executor.rb', line 20

def non_cached_rules
  no_cache_mode? ? non_cached_ability.send(:rules) : []
end

#rulesObject



12
13
14
# File 'lib/cantango/ability_executor.rb', line 12

def rules
  @rules ||= []
end