Module: Eaco::Actor

Defined in:
lib/eaco/actor.rb

Overview

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.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#can?(action, resource) ⇒ Boolean

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

Parameters:

  • action (Symbol)

    a valid action for this Resource (see DSL::Resource)

  • resource (Resource)

    an authorized resource

Returns:

  • (Boolean)

See Also:


82
83
84
# File 'lib/eaco/actor.rb', line 82

def can?(action, resource)
  resource.allows?(action, self)
end

#cannot?(*args) ⇒ Boolean

Opposite of #can?.

Parameters:

  • action (Symbol)

    a valid action for this Resource (see DSL::Resource)

  • resource (Resource)

    an authorized resource

Returns:

  • (Boolean)

92
93
94
# File 'lib/eaco/actor.rb', line 92

def cannot?(*args)
  !can?(*args)
end

#designatorsSet

Returns the designators granted to this Actor.

Returns:

  • (Set)

    the designators granted to this Actor.

See Also:


51
52
53
54
55
56
57
# 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?Boolean

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.

Returns:

  • (Boolean)

    True or False if admin logic is defined, nil if not.


68
69
70
71
72
# File 'lib/eaco/actor.rb', line 68

def is_admin?
  return unless self.class.admin_logic

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