Sha256: a13b85b608ff188b443a79909c229824ab6e7a2e4794bb1c59b766f8ba55ba82

Contents?: true

Size: 995 Bytes

Versions: 2

Compression:

Stored size: 995 Bytes

Contents

require 'open3'
require 'shellwords'

module DocverterServer
  module Runner
    class Base
      attr_reader :directory, :input_filename, :options
    
      def initialize(directory, input_filename=nil, options={})
        @directory = directory
        @input_filename = input_filename
        @options = options
      end
    
      def run
        raise "implement in subclass"
      end
    
      def generate_output_filename(extension)
        "output.#{SecureRandom.hex(10)}.#{extension}"
      end
      
      def run_command(options)
        p options
        output = ""
        cmd = Shellwords.join(options) + " 2>&1"
        p cmd
        IO.popen(cmd) do |io|
          output = io.read
        end
        if $?.exitstatus != 0
          raise DocverterServer::CommandError.new(output)
        end
      end
    
      def with_manifest
        Dir.chdir(directory) do
          yield DocverterServer::Manifest.load_file("manifest.yml")
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
docverter-server-1.0.3-java lib/docverter-server/runner/base.rb
docverter-server-1.0.2-java lib/docverter-server/runner/base.rb