Sha256: c9513378f8019d14f46d8bd090885e96beed30ce9dc262fd64d474c5d3dc7771

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

module ArubaDoubles
  module Api
    def doubles_dir
      @doubles_dir ||= Dir.mktmpdir
    end
    
    def patch_original_path
      @__aruba_doubles_original_path = (ENV['PATH'] || '').split(File::PATH_SEPARATOR)
      ENV['PATH'] = ([doubles_dir] + @__aruba_doubles_original_path).join(File::PATH_SEPARATOR)
    end

    def restore_original_path
      ENV['PATH'] = @__aruba_doubles_original_path.join(File::PATH_SEPARATOR)
    end

    def create_double(filename, options = {})
      double = File.expand_path(filename, doubles_dir)
      File.open(double, 'w') do |f|
        f.puts "#!/usr/bin/env ruby"
        f.puts "# Doubled command line application by aruba-double"
        f.puts "puts ([File.basename(__FILE__)] + ARGV).join(' ')" if @repeat_arguments
        f.puts "puts \"#{options[:stdout]}\"" if options[:stdout]
        f.puts "warn \"#{options[:stderr]}\"" if options[:stderr]
        f.puts "exit(#{options[:exit_status]})" if options[:exit_status]
      end
      FileUtils.chmod(0755, double)
    end
    
    def remove_doubles
      FileUtils.rm_r(doubles_dir) if File.directory?(doubles_dir)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
aruba-doubles-0.0.1 lib/aruba-doubles/api.rb