Module: VmParty::Utilities

Defined in:
lib/vm_party/utilities.rb

Instance Method Summary collapse

Instance Method Details

#chdir(path, &block) ⇒ Object



19
20
21
# File 'lib/vm_party/utilities.rb', line 19

def chdir(path, &block)
  Dir.chdir(path, &block)
end

#configure(flags = {}) ⇒ Object



45
46
47
48
# File 'lib/vm_party/utilities.rb', line 45

def configure(flags = {})
  flags = flags.map { |k,v| "--#{k.to_s.gsub(/_/, "-")}=#{v}" }.join(" ")
  system "./configure #{flags}"
end

#configure?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/vm_party/utilities.rb', line 41

def configure?
  exists? "Makefile"
end

#download_and_unzip(url) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/vm_party/utilities.rb', line 23

def download_and_unzip(url)
  if has_system_utility? :curl
    Dir.chdir("/tmp") do
      system("curl -s #{url} | tar -xz")
    end
  else
    raise RuntimeError, "curl not found"
  end
end

#exists?(file) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/vm_party/utilities.rb', line 15

def exists?(file)
  File.exist?(file)
end

#has_system_utility?(command) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
39
# File 'lib/vm_party/utilities.rb', line 33

def has_system_utility?(command)
  unless `which #{command}` == ""
    true
  else
    false
  end
end

#installObject



54
55
56
# File 'lib/vm_party/utilities.rb', line 54

def install
  system "sudo make install"
end

#makeObject



50
51
52
# File 'lib/vm_party/utilities.rb', line 50

def make
  system "make"
end

#prefixObject



3
4
5
# File 'lib/vm_party/utilities.rb', line 3

def prefix
  "/usr/local"
end

#remove(folder) ⇒ Object



58
59
60
61
62
# File 'lib/vm_party/utilities.rb', line 58

def remove(folder)
  if exists?(folder)
    system "sudo rm -r #{folder}"
  end
end

#run(command) ⇒ Object



7
8
9
# File 'lib/vm_party/utilities.rb', line 7

def run(command)
  system(command)
end

#sudo(command) ⇒ Object



11
12
13
# File 'lib/vm_party/utilities.rb', line 11

def sudo(command)
  run("sudo #{command}")
end