Sha256: 5bfd248deea4ff60f8cd8b3724f3c9767b280c4541dc4233120ededa725a8796

Contents?: true

Size: 1.74 KB

Versions: 1

Compression:

Stored size: 1.74 KB

Contents

module Methadone
  # Module to contain ExecutionStrategy implementations.
  # To build your own simply implement two methods:
  #
  # <tt>exception_meaning_command_not_found</tt>:: return the class that, if caught, means that the underlying command
  #                                                couldn't be found.  This is needed because currently impelmentations
  #                                                throw an exception, but they don't all throw the same one.
  module ExecutionStrategy
    # Base for any ExecutionStrategy implementation.  Currently, this is nothing more than an interface
    # specification.
    class Base
      # Executes the command and returns the results back.
      # This should do no logging or other logic other than to execute the command
      # and return the required results.
      #
      # command:: the command-line to run, as a String
      #
      # Returns an array of size 3:
      # <tt>[0]</tt>:: The standard output of the command as a String, never nil
      # <tt>[1]</tt>:: The standard error output of the command as a String, never nil
      # <tt>[2]</tt>:: A Process::Status-like objects that responds to <tt>exitstatus</tt> which returns
      #                the exit code of the command (e.g. 0 for success).
      def run_command(command)
        subclass_must_impelment!
      end

      # Returns the class that, if caught by calling #run_command, represents the underlying command
      # not existing.  For example, in MRI Ruby, if you try to execute a non-existent command,
      # you get a Errno::ENOENT.
      def exception_meaning_command_not_found
        subclass_must_impelment!
      end
    protected
      def subclass_must_impelment!; raise "subclass must implement"; end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
methadone-1.0.0.rc1 lib/methadone/execution_strategy/base.rb