Module: Trust::Actor
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/trust/actor.rb
Overview
Trust::Actor extension
Include this module if you want to check if an actor can act upon a specific subject. E.g. if your class is Actor, then include like this:
class Actor < ActiveRecord::Base
include Trust::Actor
...
end
Examples
# If the @actor can create customers, create it
if @actor.can? :create, Customer
Customer.create attributes
end
# If @actor can create accounts for the given customer, create it
if @actor.can? :create, Account, @customer
Account.create attributes
end
# It is also possible to make code more descripting for the same as above
if @actor.can? :create, Account, :parent => @customer # or, ...
if @actor.can? :create, Account, :for => @customer
Instance Method Summary collapse
Instance Method Details
#can?(action, subject, *args) ⇒ Boolean
54 55 56 57 58 59 |
# File 'lib/trust/actor.rb', line 54 def can?(action, subject, *args) = args. [:parent] ||= args.first || .delete(:for) [:by] = self Trust::Authorization.(action, subject, ) end |