Sha256: edb59b35c7aaf198a627fe58b4204cf3d2d87c5888463e794399b07dad659874

Contents?: true

Size: 733 Bytes

Versions: 10

Compression:

Stored size: 733 Bytes

Contents

module Orats
  # manage detecting processes
  module Process
    def exit_if_process(detect_method, *processes)
      result = process_detect(detect_method)

      processes.each do |process|
        task "Check if #{process} is available"

        exit 1 if process_unusable?("#{result} #{process}", process)
      end
    end

    private

    def process_detect(method)
      if method == :not_found
        'which'
      elsif method == :not_running
        'ps cax | grep'
      end
    end

    def process_unusable?(command, process)
      out = run(command, capture: true)

      if out.empty?
        error "Cannot detect #{process}",
              'trying to do `which` on it'
      end

      out.empty?
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
orats-0.9.7 lib/orats/process.rb
orats-0.9.6 lib/orats/process.rb
orats-0.9.5 lib/orats/process.rb
orats-0.9.4 lib/orats/process.rb
orats-0.9.3 lib/orats/process.rb
orats-0.9.2 lib/orats/process.rb
orats-0.9.1 lib/orats/process.rb
orats-0.9.0 lib/orats/process.rb
orats-0.8.1 lib/orats/process.rb
orats-0.8.0 lib/orats/process.rb