Class: CanTango::Permits::AccountPermit
- Inherits:
-
CanTango::Permit
- Object
- CanTango::Permit
- CanTango::Permits::AccountPermit
- Defined in:
- lib/cantango/permits/account_permit.rb,
lib/cantango/permits/account_permit/finder.rb,
lib/cantango/permits/account_permit/builder.rb
Defined Under Namespace
Class Method Summary collapse
- .account_type_name(clazz) ⇒ Object
- .hash_key ⇒ Object
- .inherited(base_clazz) ⇒ Object
- .type ⇒ Object
Instance Method Summary collapse
-
#initialize(ability) ⇒ AccountPermit
constructor
creates the permit.
-
#permit? ⇒ Boolean
In a specific Role based Permit you can use def permit? user, options = {} …
- #permit_name ⇒ Object (also: #account_type)
- #valid_for?(subject) ⇒ Boolean
Constructor Details
#initialize(ability) ⇒ AccountPermit
creates the permit
27 28 29 |
# File 'lib/cantango/permits/account_permit.rb', line 27 def initialize ability super end |
Class Method Details
.account_type_name(clazz) ⇒ Object
15 16 17 |
# File 'lib/cantango/permits/account_permit.rb', line 15 def self.account_type_name clazz clazz.name.demodulize.gsub(/(.*)(AccountPermit)/, '\1').underscore.to_sym end |
.hash_key ⇒ Object
53 54 55 |
# File 'lib/cantango/permits/account_permit.rb', line 53 def self.hash_key account_type_name(self) end |
.inherited(base_clazz) ⇒ Object
7 8 9 |
# File 'lib/cantango/permits/account_permit.rb', line 7 def self.inherited(base_clazz) CanTango.config.permits.register_permit_class account_type_name(base_clazz), base_clazz, type, account_name(base_clazz) end |
.type ⇒ Object
11 12 13 |
# File 'lib/cantango/permits/account_permit.rb', line 11 def self.type :account end |
Instance Method Details
#permit? ⇒ Boolean
In a specific Role based Permit you can use
def permit? user, options = {}
... permission logic follows
This will call the Permit::Base#permit? instance method (the method below) It will only return true if the user matches the role of the Permit class and the
If these confitions are not met, it will return false and thus the outer permit will not run the permission logic to follow
Normally super for #permit? should not be called except for this case, or if subclassing another Permit than Permit::Base
44 45 46 |
# File 'lib/cantango/permits/account_permit.rb', line 44 def permit? super end |
#permit_name ⇒ Object Also known as: account_type
19 20 21 |
# File 'lib/cantango/permits/account_permit.rb', line 19 def permit_name self.class.account_type_name self.class end |
#valid_for?(subject) ⇒ Boolean
48 49 50 51 |
# File 'lib/cantango/permits/account_permit.rb', line 48 def valid_for? subject debug_invalid if !(subject_name == account_name) subject_name == account_name end |