Sha256: a93a66459f56e421a82bcca943750cdb1632d162f9a34cb925acc3f31979b4db

Contents?: true

Size: 1.12 KB

Versions: 19

Compression:

Stored size: 1.12 KB

Contents

module Minke
  module Helpers
    class Shell
      def initialize logger
        @logger = logger
      end

      ##
      # Executes a shell command and returns the return status
      def execute command, ignore_error=false
        @logger.debug command
        
        Open3.popen2e(command) do |stdin, stdout_err, wait_thr|
          while line = stdout_err.gets
            @logger.debug line
          end
          
          exit_status = wait_thr.value
          unless exit_status.success? || ignore_error == true
            raise "Error executing command: #{command}"
          end
        end
      end

      def execute_and_return command
        log = `#{command}`
        return log.strip
      end

      def mktmpdir
        Dir.mktmpdir
      end

      def remove_entry_secure dir
        FileUtils.remove_entry_secure dir
      end

      def write_file filename, data
        File.open(filename, 'w') { |file| file.write(data) }
      end

      def read_file filename
        File.open(filename, 'rb') { |file| file.read }.strip
      end

      def exist? filename
        File.exist? filename
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
minke-1.15.0 lib/minke/helpers/shell.rb
minke-1.14.5 lib/minke/helpers/shell.rb
minke-1.14.4 lib/minke/helpers/shell.rb
minke-1.14.3 lib/minke/helpers/shell.rb
minke-1.14.2 lib/minke/helpers/shell.rb
minke-1.14.1 lib/minke/helpers/shell.rb
minke-1.14.0 lib/minke/helpers/shell.rb
minke-1.13.20 lib/minke/helpers/shell.rb
minke-1.13.19 lib/minke/helpers/shell.rb
minke-1.13.18 lib/minke/helpers/shell.rb
minke-1.13.16 lib/minke/helpers/shell.rb
minke-1.13.15 lib/minke/helpers/shell.rb
minke-1.13.14 lib/minke/helpers/shell.rb
minke-1.13.13 lib/minke/helpers/shell.rb
minke-1.13.12 lib/minke/helpers/shell.rb
minke-1.13.11 lib/minke/helpers/shell.rb
minke-1.13.10 lib/minke/helpers/shell.rb
minke-1.13.9 lib/minke/helpers/shell.rb
minke-1.13.8 lib/minke/helpers/shell.rb