Class: Utility

Inherits:
Object
  • Object
show all
Defined in:
lib/dex-oracle/utility.rb

Class Method Summary collapse

Class Method Details

.create_zip(zip, name_to_file) ⇒ Object



15
16
17
18
19
# File 'lib/dex-oracle/utility.rb', line 15

def self.create_zip(zip, name_to_file)
  Zip::File.open(zip, Zip::File::CREATE) do |zf|
    name_to_file.each { |n, f| zf.add(n, f) }
  end
end

.extract_file(zip, name, dest) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/dex-oracle/utility.rb', line 21

def self.extract_file(zip, name, dest)
  Zip::File.open(zip) do |zf|
    zf.each do |e|
      next unless e.name == name
      e.extract(dest) { true } # overwrite
      break
    end
  end
end

.update_zip(zip, name, target) ⇒ Object



31
32
33
34
35
36
# File 'lib/dex-oracle/utility.rb', line 31

def self.update_zip(zip, name, target)
  Zip::File.open(zip) do |zf|
    zf.remove(name)
    zf.add(name, target.path)
  end
end

.which(cmd) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/dex-oracle/utility.rb', line 4

def self.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
  nil
end