module Eaco::Actor

An Actor is an entity whose access to Resources is discretionary, depending on the Role this actor has in the ACL.

The role of this Actor is calculated from the {Designator} that the actor instance has, and the {ACL} instance attached to the {Resource}.

@see ACL @see Resource @see Resource.role_of @see DSL::Actor

Public Class Methods

included(base) click to toggle source

@private

# File lib/eaco/actor.rb, line 19
def self.included(base)
  base.extend ClassMethods
end

Public Instance Methods

can?(action, resource) click to toggle source

Checks wether the given Resource allows this Actor to perform the given action.

@param action [Symbol] a valid action for this Resource (see {DSL::Resource}) @param resource [Resource] an authorized resource

@see Resource

# File lib/eaco/actor.rb, line 82
def can?(action, resource)
  resource.allows?(action, self)
end
cannot?(*args) click to toggle source

Opposite of {#can?}.

@param (see can?) @return (see can?)

# File lib/eaco/actor.rb, line 92
def cannot?(*args)
  !can?(*args)
end
designators() click to toggle source

@return [Set] the designators granted to this Actor.

@see Designator

# File lib/eaco/actor.rb, line 51
def designators
  Set.new.tap do |ret|
    self.class.designators.each do |_, designator|
      ret.merge designator.harvest(self)
    end
  end
end
is_admin?() click to toggle source

Checks whether this Actor fulfills the admin logic.

This logic is called by Resource Adapters' accessible_by, that returns the full collection, and by {Resource#allows?}, that bypassess access checks always returning true.

@return [Boolean] True or False if admin logic is defined, nil if not.

# File lib/eaco/actor.rb, line 68
def is_admin?
  return unless self.class.admin_logic

  instance_exec(self, &self.class.admin_logic)
end