Class: CanTango::Engine::Permits
- Inherits:
-
Ability::Executor::Base
- Object
- Ability::Executor::Base
- CanTango::Engine::Permits
- Includes:
- Ability::Helper::User
- Defined in:
- lib/cantango/permits_ext/engine/permits.rb
Instance Method Summary collapse
- #calc_rules ⇒ Object
- #engine_name ⇒ Object (also: #cache_key)
- #executor(type, permits) ⇒ Object
-
#initialize(ability) ⇒ Permits
constructor
A new instance of Permits.
- #permit_class_names ⇒ Object
-
#permits_of(type) ⇒ Object
by default, only execute permits for which the user has a role or a role group also execute any permit marked as special.
- #valid? ⇒ Boolean
Constructor Details
#initialize(ability) ⇒ Permits
Returns a new instance of Permits.
6 7 8 |
# File 'lib/cantango/permits_ext/engine/permits.rb', line 6 def initialize ability super end |
Instance Method Details
#calc_rules ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/cantango/permits_ext/engine/permits.rb', line 10 def calc_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 |
#engine_name ⇒ Object Also known as: cache_key
22 23 24 |
# File 'lib/cantango/permits_ext/engine/permits.rb', line 22 def engine_name :permit end |
#executor(type, permits) ⇒ Object
18 19 20 |
# File 'lib/cantango/permits_ext/engine/permits.rb', line 18 def executor type, permits CanTango::Ability::Executor::PermitType.new self, type, permits_of(type) end |
#permit_class_names ⇒ Object
38 39 40 |
# File 'lib/cantango/permits_ext/engine/permits.rb', line 38 def permit_class_names @permit_class_names ||= permits.map{|p| p.class.to_s} end |
#permits_of(type) ⇒ Object
by default, only execute permits for which the user has a role or a role group also execute any permit marked as special
34 35 36 |
# File 'lib/cantango/permits_ext/engine/permits.rb', line 34 def permits_of type @permits ||= permit_factory(type).create end |
#valid? ⇒ Boolean
26 27 28 29 |
# File 'lib/cantango/permits_ext/engine/permits.rb', line 26 def valid? return false if !valid_mode? permits.empty? ? invalid : true end |