Sha256: 1553edec65ff596574a3dce085fd2cd1566502aa2cd7743d198b63e98e07d62e

Contents?: true

Size: 924 Bytes

Versions: 3

Compression:

Stored size: 924 Bytes

Contents

#
# Command
#

module VCSRuby
  class Command
    attr_reader :name, :available
    def initialize name, command
      @name = name
      @command = which(command)
      @available = !!@command
    end

    def execute parameter, streams = "2> /dev/null"
      raise "Command '#{name}' not available" unless available

      if Tools::windows?
        `cmd /C #{@command} #{parameter}`
      else
        `#{@command} #{parameter} #{streams}`
      end
    end

private
    # http://stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby
    def which cmd
      exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
      ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
        exts.each do |ext|
          exe = File.join(path, "#{cmd}#{ext}")
          return exe if File.executable?(exe) && !File.directory?(exe)
        end
      end
      return nil
    end
  end
 end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vcs_ruby-0.8.2 lib/command.rb
vcs_ruby-0.8.1 lib/command.rb
vcs_ruby-0.8.0 lib/command.rb