Class: CanTango::PermitEngine

Inherits:
Engine
  • Object
show all
Includes:
Ability::Executor, Ability::RoleHelpers, Ability::UserHelpers
Defined in:
lib/cantango/permit_engine.rb,
lib/cantango/permit_engine/util.rb,
lib/cantango/permit_engine/finder.rb,
lib/cantango/permit_engine/builder.rb,
lib/cantango/permit_engine/factory.rb,
lib/cantango/permit_engine/executor.rb,
lib/cantango/permit_engine/builder/base.rb,
lib/cantango/permit_engine/role_matcher.rb,
lib/cantango/permit_engine/compatibility.rb,
lib/cantango/permit_engine/executor/base.rb,
lib/cantango/permit_engine/executor/system.rb,
lib/cantango/permit_engine/executor/abstract.rb,
lib/cantango/permit_engine/builder/special_permits.rb

Defined Under Namespace

Modules: Builder, Compatibility, Executor, RoleMatcher, Util Classes: Factory, Finder

Instance Attribute Summary

Attributes inherited from Engine

#ability

Instance Method Summary collapse

Methods included from Ability::UserHelpers

#user, #user_account, #user_key_field

Methods included from 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 Ability::Executor

#cache, #clear_rules!, #execute!, #rules

Methods included from Ability::CacheHelpers

#cache

Methods included from Helpers::Debug

#debug

Methods inherited from Engine

#execute!

Constructor Details

#initialize(ability) ⇒ PermitEngine

Returns a new instance of PermitEngine.



10
11
12
# File 'lib/cantango/permit_engine.rb', line 10

def initialize ability
  super
end

Instance Method Details

#engine_nameObject Also known as: cache_key



26
27
28
# File 'lib/cantango/permit_engine.rb', line 26

def engine_name
  :permit
end

#executor(type, permits) ⇒ Object



22
23
24
# File 'lib/cantango/permit_engine.rb', line 22

def executor type, permits
  CanTango::Permits::Executor.new self, type, permits
end

#permit_class_namesObject



42
43
44
# File 'lib/cantango/permit_engine.rb', line 42

def permit_class_names
  @permit_class_names ||= permits.map{|p| p.class.to_s}
end

#permit_rulesObject



14
15
16
17
18
19
20
# File 'lib/cantango/permit_engine.rb', line 14

def permit_rules
  # push result of each permit type execution into main ability rules array
  permits.each_pair do |type, permits|
    perm_rules = executor(type, permits).execute!
    rules << perm_rules if !perm_rules.blank?
  end
end

#permitsObject

by default, only execute permits for which the user has a role or a role group also execute any permit marked as special



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

def permits
  @permits ||= permit_factory.build!
end

#valid?Boolean

Returns:

  • (Boolean)


30
31
32
33
# File 'lib/cantango/permit_engine.rb', line 30

def valid?
  return false if !valid_mode?
  permits.empty? ? invalid : true
end