class Consent::Ability
Defines a CanCan(Can)::Ability class based on a permissions hash
Public Class Methods
new(*args, apply_defaults: true)
click to toggle source
# File lib/consent/ability.rb, line 8 def initialize(*args, apply_defaults: true) @context = *args apply_defaults! if apply_defaults end
Public Instance Methods
consent(**kwargs)
click to toggle source
# File lib/consent/ability.rb, line 27 def consent(**kwargs) consent!(**kwargs) rescue Consent::ViewNotFound nil end
consent!(subject: nil, action: nil, view: nil)
click to toggle source
# File lib/consent/ability.rb, line 13 def consent!(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
Private Instance Methods
apply_defaults!()
click to toggle source
# File lib/consent/ability.rb, line 35 def apply_defaults! Consent.subjects.each do |subject| subject.actions.each do |action| next unless action.default_view consent( subject: subject.key, action: action.key, view: action.default_view ) end end end