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

parent[RW]
test[RW]

Public Class Methods

new(args) click to toggle source

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

api_context?() click to toggle source

@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
child_context?() click to toggle source

@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(result) click to toggle source

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
rails_context?() click to toggle source

@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
rake_context?() click to toggle source

@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
root_context() click to toggle source

@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
test_context?() click to toggle source

@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
testing() { |test| ... } click to toggle source

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

execute_internal(result) click to toggle source

@!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