Module: Walruz::Subject
- Defined in:
- lib/walruz/subject.rb
Overview
This module provides the methods that enable a subject to register the diferent actions that can be performed to it, and associates the policies that apply to each of these actions.
Associating policies with actions on the subject.
To associate policies and actions related to a subject, we use the check_authorizations
method, this will receive a Hash, where the keys are the name of the actions, and the values are the policies associated to this actions.
Example:
class Profile < ActiveRecord::Base
include Walruz::Subject
belongs_to :user
:read => ProfileReadPolicy,
:update => ProfileUpdatePolicy
end
Once the actions are registered on the subject, you can check if an actor can perform an action on it, using the Walruz::Actor
methods
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(base) ⇒ Object
:nodoc:.
Class Method Details
.included(base) ⇒ Object
:nodoc:
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/walruz/subject.rb', line 27 def self.included(base) # :nodoc: base.class_eval do def self._walruz_policies=(policies) @_walruz_policies = policies end def self._walruz_policies @_walruz_policies end extend ClassMethods end end |