Class: PunditRolePlay::Permissions
- Inherits:
-
Object
- Object
- PunditRolePlay::Permissions
- Defined in:
- lib/pundit_role_play/permissions.rb
Instance Attribute Summary collapse
-
#permissions ⇒ Object
readonly
Returns the value of attribute permissions.
Instance Method Summary collapse
- #[](resource) ⇒ Object
- #can?(operation, resource) ⇒ Boolean
-
#initialize(role) ⇒ Permissions
constructor
A new instance of Permissions.
Constructor Details
#initialize(role) ⇒ Permissions
Returns a new instance of Permissions.
7 8 9 10 11 12 13 14 |
# File 'lib/pundit_role_play/permissions.rb', line 7 def initialize(role) = role::PERMISSIONS rescue TypeError => e # Handle the case where the role is nil raise e unless role.nil? = {} end |
Instance Attribute Details
#permissions ⇒ Object (readonly)
Returns the value of attribute permissions.
5 6 7 |
# File 'lib/pundit_role_play/permissions.rb', line 5 def end |
Instance Method Details
#[](resource) ⇒ Object
23 24 25 |
# File 'lib/pundit_role_play/permissions.rb', line 23 def [](resource) [resource.to_sym] end |
#can?(operation, resource) ⇒ Boolean
16 17 18 19 20 21 |
# File 'lib/pundit_role_play/permissions.rb', line 16 def can?(operation, resource) # If you can write to a resource, you can also read from it return true if [resource.to_sym] == :write [resource.to_sym] == operation.to_sym end |