lib/demiurge/action_item.rb
# This is a raw, low-level way to execute an action of an
# ActionItem. It doesn't wait for Intentions.  It doesn't send
# extra notifications. It doesn't offer or give a chance to cancel
# the action.  It just runs.
#
# @param action_name [String] The name of the action to run. Must already be registered.
# @param args [Array] Additional arguments to pass to the action's code block
# @param current_intention [nil, Intention] Current intention being executed, if any. This is used for to cancel an intention, if necessary
# @return [void]
# @since 0.0.1
This is a raw, low-level way to execute an action of an
ActionItem. It doesn't wait for Intentions.  It doesn't send
extra notifications. It doesn't offer or give a chance to cancel
the action.  It just runs.
This is a raw low - level way to execute an action of an ActionItem . It doesn ' t wait for Intentions . It doesn ' t send extra notifications . It doesn ' t offer or give a chance to cancel the action . It just runs .
def run_action(action_name, *args, current_intention: nil)
      action = get_action(action_name)
      raise ::Demiurge::Errors::NoSuchActionError.new("No such action as #{action_name.inspect} for #{@name.inspect}!",
                                                      "item" => self.name, "action" => action_name,
                                                      execution_context: @engine.execution_context) unless action
      block = action["block"]
      raise ::Demiurge::Errors::NoSuchActionError.new("Action was never defined for #{action_name.inspect} of object #{@name.inspect}!",
                                                      "item" => self.name, "action" => action_name,
                                                      execution_context: @engine.execution_context) unless block
      runner_constructor_args = {}
      if action["engine_code"]
        block_runner_type = ActionItemInternal::EngineBlockRunner
      elsif self.agent?
        block_runner_type = ActionItemInternal::AgentBlockRunner
        runner_constructor_args[:current_intention] = current_intention
      else
        block_runner_type = ActionItemInternal::ActionItemBlockRunner
        runner_constructor_args[:current_intention] = current_intention
      end
      block_runner = block_runner_type.new(self, **runner_constructor_args)
      begin
        @engine.push_context("running_action" => action_name, "running_action_item" => @name) do
          block_runner.instance_exec(*args, &block)
        end
      rescue
        raise ::Demiurge::Errors::BadScriptError.new("Script error of type #{$!.class} with message: #{$!.message}",
                                                     { "runner type": block_runner_type.to_s, "action" => action_name, },
                                                     execution_context: @engine.execution_context);
      end
      nil
    end
def run_action ( action_name , * args , current_intention : nil ) action = get_action ( action_name ) raise :: Demiurge :: Errors :: NoSuchActionError . new ( "No such action as #{action_name.inspect} for #{@name.inspect}!" , "item" => self . name , "action" => action_name , execution_context : @engine . execution_context ) unless action block = action [ "block" ] raise :: Demiurge :: Errors :: NoSuchActionError . new ( "Action was never defined for #{action_name.inspect} of object #{@name.inspect}!" , "item" => self . name , "action" => action_name , execution_context : @engine . execution_context ) unless block runner_constructor_args = { } if action [ "engine_code" ] block_runner_type = ActionItemInternal :: EngineBlockRunner elsif self . agent? block_runner_type = ActionItemInternal :: AgentBlockRunner runner_constructor_args [ :current_intention ] = current_intention else block_runner_type = ActionItemInternal :: ActionItemBlockRunner runner_constructor_args [ :current_intention ] = current_intention end block_runner = block_runner_type . new ( self , ** runner_constructor_args ) begin @engine . push_context ( "running_action" => action_name , "running_action_item" => @name ) do block_runner . instance_exec ( * args , & block ) end rescue raise :: Demiurge :: Errors :: BadScriptError . new ( "Script error of type #{$!.class} with message: #{$!.message}" , { "runner type" : block_runner_type . to_s , "action" => action_name , } , execution_context : @engine . execution_context ) ; end nil end
This is a raw, low-level way to execute an action of an
ActionItem.
This is a raw low - level way to execute an action of an ActionItem .
# TODO: can we save block runners between actions? #STDERR.puts "#{$!.message}\n#{$!.backtrace.join("\n")}"
None
void
action_name
The name of the action to run. Must already be registered.
The name of the action to run . Must already be registered .
args
Additional arguments to pass to the action's code block
Additional arguments to pass to the action ' s code block
current_intention
Current intention being executed, if any. This is used for to cancel an intention, if necessary
Current intention being executed if any . This is used for to cancel an intention if necessary
since
None