Module: Kankri::PrivilegeSubject
- Defined in:
- lib/kankri/privilege_subject.rb
Overview
Mixin that allows classes to require privileges from a PrivilegeSet
This expects the including class to define a method, 'privilege_key', which identifies the object in the privilege set.
Instance Method Summary collapse
-
#can?(operation, privilege_set) ⇒ Boolean
Checks whether a privilege is granted for this object.
-
#fail_if_cannot(operation, privilege_set) ⇒ void
Raises an exception if a privilege is not granted for this object.
Instance Method Details
#can?(operation, privilege_set) ⇒ Boolean
Checks whether a privilege is granted for this object
This looks in the privilege set under the key returned by #privilege_key.
28 29 30 |
# File 'lib/kankri/privilege_subject.rb', line 28 def can?(operation, privilege_set) privilege_set.has?(operation, privilege_key) end |
#fail_if_cannot(operation, privilege_set) ⇒ void
This method returns an undefined value.
Raises an exception if a privilege is not granted for this object
This looks in the privilege set under the key returned by #privilege_key.
43 44 45 |
# File 'lib/kankri/privilege_subject.rb', line 43 def fail_if_cannot(operation, privilege_set) privilege_set.require(operation, privilege_key) end |