Module: MimeActor::Stage

Extended by:
ActiveSupport::Concern
Includes:
Callbacks, Logging, Rescue
Included in:
Action
Defined in:
lib/mime_actor/stage.rb

Overview

# MimeActor Stage

Stage provides helper methods for actor lookup and invocation.

Constant Summary

Constants included from Callbacks

Callbacks::LIFECYCLES

Instance Method Summary collapse

Methods included from Rescue

#rescue_actor

Methods included from Callbacks

#run_act_callbacks

Instance Method Details

#cue_actor(actor, *args, action:, format:) ⇒ Object

Calls the ‘actor` and passing arguments to it. If a block is given, the result from the `actor` method will be yieled to the block.

NOTE: method call on actor if it is String or Symbol. Proc#call if actor is Proc

Parameters:

  • actor

    either a method name or a Proc to evaluate

  • args

    arguments to be passed when calling the actor



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/mime_actor/stage.rb', line 37

def cue_actor(actor, *args, action:, format:)
  dispatcher = MimeActor::Dispatcher.build(actor, *args)
  raise TypeError, "invalid actor, got: #{actor.inspect}" unless dispatcher

  self.class.validate!(:format, format)

  run_act_callbacks(action: action, format: format) do
    result = dispatcher.call(self)
    block_given? ? yield(result) : result
  end
rescue MimeActor::ActorNotFound => e
  logger.error { "actor error, cause: #{e.inspect}" } unless raise_on_actor_error
  raise e if raise_on_actor_error
rescue StandardError => e
  rescued = rescue_actor(e, action: action, format: format)
  rescued || raise
end