Sha256: 7c463f70d65731b7178a66ffaad333c76e288c4ef9ab5e4dfcb8302afe12f97c

Contents?: true

Size: 1.06 KB

Versions: 5

Compression:

Stored size: 1.06 KB

Contents

# -*- encoding : utf-8 -*-
module PathHelpers
  def reject_paths_with_cmd(cmd)
    @original_path = ENV['PATH']
    # make a new subdir that still contains cmds
    tmpbindir = File.expand_path(File.join @dirs, 'bin')
    FileUtils.mkdir_p tmpbindir

    preseve_cmds_in_path(['git', 'mplayer'], tmpbindir)

    exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
    newpaths = ENV['PATH'].split(File::PATH_SEPARATOR).reject do |path|
      found_cmd = false
      exts.each do |ext|
        exe = "#{path}/#{cmd}#{ext}"
        found_cmd = true if File.executable? exe
      end
      found_cmd
    end

    # add the temporary directory with git in it back into the path
    newpaths << tmpbindir
    ENV['PATH'] = newpaths.join(File::PATH_SEPARATOR)
  end

  def preseve_cmds_in_path(cmds, tmpbindir)
    cmds.each do |cmd|
      whichcmd = Lolcommits::Configuration.command_which(cmd)
      unless whichcmd.nil?
        FileUtils.ln_s whichcmd, File.join(tmpbindir, File.basename(whichcmd))
      end
    end
  end

  def reset_path
    ENV['PATH'] = @original_path
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
lolcommits-0.5.7 features/support/path_helpers.rb
lolcommits-0.5.6 features/support/path_helpers.rb
lolcommits-0.5.5 features/support/path_helpers.rb
lolcommits-0.5.4 features/support/path_helpers.rb
lolcommits-0.5.3 features/support/path_helpers.rb