Class: CanTango::Ability

Inherits:
Object
  • Object
show all
Includes:
CanCan::Ability, CacheHelpers, EngineHelpers, MasqueradeHelpers, PermissionHelpers, PermitHelpers, RoleHelpers, UserHelpers, PermitEngine::Util
Defined in:
lib/cantango/ability.rb,
lib/cantango/ability/cache.rb,
lib/cantango/ability/scope.rb,
lib/cantango/adapter/moneta.rb,
lib/cantango/ability/executor.rb,
lib/cantango/adapter/compiler.rb,
lib/cantango/ability/cache/key.rb,
lib/cantango/ability/cache/reader.rb,
lib/cantango/ability/cache/writer.rb,
lib/cantango/ability/role_helpers.rb,
lib/cantango/ability/user_helpers.rb,
lib/cantango/ability/cache_helpers.rb,
lib/cantango/ability/cache/kompiler.rb,
lib/cantango/ability/engine_helpers.rb,
lib/cantango/ability/permit_helpers.rb,
lib/cantango/ability/cache/base_cache.rb,
lib/cantango/ability/cache/rules_cache.rb,
lib/cantango/ability/cache/moneta_cache.rb,
lib/cantango/ability/masquerade_helpers.rb,
lib/cantango/ability/permission_helpers.rb,
lib/cantango/ability/cache/session_cache.rb

Direct Known Subclasses

AbilityExecutor, CachedAbility

Defined Under Namespace

Modules: CacheHelpers, EngineHelpers, Executor, MasqueradeHelpers, PermissionHelpers, PermitHelpers, RoleHelpers, UserHelpers Classes: Cache, Scope

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RoleHelpers

#role_groups, #roles

Methods included from Helpers::RoleMethods

#has_role_group_meth, #has_role_meth, #role_groups_list_meth, #roles_list_meth

Methods included from UserHelpers

#user, #user_account, #user_key_field

Methods included from PermitHelpers

#permits?

Methods included from MasqueradeHelpers

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

Methods included from CacheHelpers

#cache

Methods included from 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 = {}) ⇒ Ability

Equivalent to a CanCan Ability#initialize call which executes all the permission logic



15
16
17
18
19
20
21
22
23
# File 'lib/cantango/ability.rb', line 15

def initialize candidate, options = {}
  raise "Candidate must be something!" if !candidate
  @candidate, @options = candidate, options

  clear_rules!
  permit_rules

  execute_engines! if engines_on?
end

Instance Attribute Details

#candidateObject (readonly)

Returns the value of attribute candidate.



11
12
13
# File 'lib/cantango/ability.rb', line 11

def candidate
  @candidate
end

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/cantango/ability.rb', line 11

def options
  @options
end

Instance Method Details

#cached?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/cantango/ability.rb', line 27

def cached?
  false
end

#clear_rules!Object



34
35
36
# File 'lib/cantango/ability.rb', line 34

def clear_rules!
  @rules ||= default_rules
end

#configObject



48
49
50
# File 'lib/cantango/ability.rb', line 48

def config
  CanTango.config
end

#permit_rulesObject



31
32
# File 'lib/cantango/ability.rb', line 31

def permit_rules
end

#sessionObject



38
39
40
# File 'lib/cantango/ability.rb', line 38

def session
  @session = options[:session] || {} # seperate session cache for each type of user?
end

#subjectObject



42
43
44
45
46
# File 'lib/cantango/ability.rb', line 42

def subject
  return candidate.active_user if masquerade_user?
  return candidate. if masquerade_account?
  candidate
end