Class: Consent::Ability
- Inherits:
-
Object
- Object
- Consent::Ability
- Includes:
- CanCan::Ability
- Defined in:
- lib/consent/ability.rb
Overview
Defines a CanCan(Can)::Ability class based on a permissions hash
Instance Method Summary collapse
- #consent(**kwargs) ⇒ Object
- #consent!(subject: nil, action: nil, view: nil) ⇒ Object
-
#initialize(*args, apply_defaults: true) ⇒ Ability
constructor
A new instance of Ability.
Constructor Details
#initialize(*args, apply_defaults: true) ⇒ Ability
Returns a new instance of Ability.
8 9 10 11 |
# File 'lib/consent/ability.rb', line 8 def initialize(*args, apply_defaults: true) @context = *args apply_defaults! if apply_defaults end |
Instance Method Details
#consent(**kwargs) ⇒ Object
27 28 29 30 31 |
# File 'lib/consent/ability.rb', line 27 def (**kwargs) (**kwargs) rescue Consent::ViewNotFound nil end |
#consent!(subject: nil, action: nil, view: nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/consent/ability.rb', line 13 def (subject: nil, action: nil, view: nil) view = case view when Consent::View view when Symbol Consent.find_view(subject, action, view) end can( action, subject, view&.conditions(*@context), &view&.object_conditions(*@context) ) end |