Class: CanTango::Permits::UserPermit
- Inherits:
-
CanTango::Permit
- Object
- CanTango::Permit
- CanTango::Permits::UserPermit
- Defined in:
- lib/cantango/permits/user_permit.rb,
lib/cantango/permits/user_permit/finder.rb,
lib/cantango/permits/user_permit/builder.rb
Defined Under Namespace
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(ability) ⇒ UserPermit
constructor
creates the permit.
-
#permit? ⇒ Boolean
In a specific Role based Permit you can use def permit? user, options = {} …
-
#user_type ⇒ Object
fx for User user class, becomes simply UserPermit.
Constructor Details
#initialize(ability) ⇒ UserPermit
creates the permit
27 28 29 |
# File 'lib/cantango/permits/user_permit.rb', line 27 def initialize ability super end |
Class Method Details
.inherited(base_clazz) ⇒ Object
7 8 9 |
# File 'lib/cantango/permits/user_permit.rb', line 7 def self.inherited(base_clazz) CanTango.config.permits.register_permit_class user_type_name(base_clazz), base_clazz, type, account_name(base_clazz) end |
.type ⇒ Object
11 12 13 |
# File 'lib/cantango/permits/user_permit.rb', line 11 def self.type :user end |
.user_type_name(clazz) ⇒ Object
15 16 17 |
# File 'lib/cantango/permits/user_permit.rb', line 15 def self.user_type_name clazz clazz.name.demodulize.gsub(/(.*)(Permit)/, '\1').underscore.to_sym 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
45 46 47 |
# File 'lib/cantango/permits/user_permit.rb', line 45 def permit? super end |
#user_type ⇒ Object
fx for User user class, becomes simply UserPermit
20 21 22 |
# File 'lib/cantango/permits/user_permit.rb', line 20 def user_type self.class.user_type_name self.class end |