class ActionCommand::Executable
Root class for action commands that can be executed by this library. Override execute_internal
to implement one, call one of the variants of ActionCommand.execute_… to execute one.
Attributes
Public Class Methods
Do not call new directly, instead use ActionCommand#execute_… variants.
# File lib/action_command/executable.rb, line 11 def initialize(args) self.class.describe_io.process_input(self, args) end
Public Instance Methods
@return true if this command was executed using ActionCommand.execute_api
# File lib/action_command/executable.rb, line 39 def api_context? return root_context == ActionCommand::CONTEXT_API end
@return true if this command is a child of another command
# File lib/action_command/executable.rb, line 45 def child_context? return !parent.is_a?(Symbol) end
Execute the logic of a command. Should not usually be called directly. Command executors should call one of the ActionCommand.execute_… variants. Command implementors should override execute_internal.
@return [ActionCommand::Result]
# File lib/action_command/executable.rb, line 54 def execute(result) execute_internal(result) self.class.describe_io.process_output(self, result) return result end
@return true if this command was executed using ActionCommand.execute_rails
# File lib/action_command/executable.rb, line 29 def rails_context? return root_context == ActionCommand::CONTEXT_RAILS end
@return true if this command was executed using ActionCommand.execute_rake
# File lib/action_command/executable.rb, line 34 def rake_context? return root_context == ActionCommand::CONTEXT_RAKE end
@return [Symbol] the symbol indicating what context this action was executed in, see the ActionCommand::CONTEXT_ constants.
# File lib/action_command/executable.rb, line 17 def root_context context = parent context = context.parent until context.is_a? Symbol return context end
@return true if this command was executed using ActionCommand.execute_test
# File lib/action_command/executable.rb, line 24 def test_context? return root_context == ActionCommand::CONTEXT_TEST end
Call this within a commands execution if you’d like to perform validations within the testing context.
@yield [context] Yields back the testing context that you
passed in to ActionCommand#execute_test.
# File lib/action_command/executable.rb, line 64 def testing yield @test if @test end
Protected Instance Methods
@!visibility public Override this method to implement the logic of your command @param result [ActionCommand::Result] a result object where you can store
the results of your logic, or indicate that the command failed.
# File lib/action_command/executable.rb, line 75 def execute_internal(result) end