class Eaco::DSL::Actor
Parses the Actor
DSL
, that describes how to harvest {Designator}s from an {Actor} and how to identify it as an admin
, or superuser.
actor User do admin do |user| user.admin? end designators do authenticated from: :class user from: :id group from: :group_ids end end
Public Class Methods
Looks up the given designator implementation by its name
.
@param name [Symbol] the designator name.
@raise [Eaco::Malformed] if the designator is not found.
@return [Class]
# File lib/eaco/dsl/actor.rb, line 113 def find_designator(name) all_designators.fetch(name.intern) rescue KeyError raise Malformed, "Designator not found: #{name.inspect}" end
Makes an application model a valid {Eaco::Actor}.
@see Eaco::Actor
# File lib/eaco/dsl/actor.rb, line 28 def initialize(*) super target_eval do include Eaco::Actor def designators @_designators end def admin_logic @_admin_logic end end end
Saves the given designators in the global designators registry.
@param new_designators [Hash]
@return [Hash] the designators registry.
# File lib/eaco/dsl/actor.rb, line 127 def register_designators(new_designators) all_designators.update(new_designators) end
Private Class Methods
@return [Hash] a registry of all the defined designators.
# File lib/eaco/dsl/actor.rb, line 135 def all_designators @_all_designators ||= {} end
Public Instance Methods
Defines the boolean logic that determines whether an {Actor} is an admin. Usually you'll have an admin?
method on your model, that you can call from here. Or, feel free to just return false
to disable this functionality.
Example:
actor User do admin do |user| user.admin? end end
@param block [Proc] @return [void]
# File lib/eaco/dsl/actor.rb, line 97 def admin(&block) target_eval do @_admin_logic = block end end
# File lib/eaco/dsl/actor.rb, line 38 def admin_logic @_admin_logic end
# File lib/eaco/dsl/actor.rb, line 34 def designators @_designators end