Class: Getme::Utilities
- Inherits:
-
Object
- Object
- Getme::Utilities
- Defined in:
- lib/getme/utilities.rb
Instance Method Summary collapse
- #cmd(badass, url) ⇒ Object
-
#cmd?(cmd) ⇒ Boolean
check if cmd available from system.
- #downloader ⇒ Object
Instance Method Details
#cmd(badass, url) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/getme/utilities.rb', line 3 def cmd(badass, url) if badass == :wget `wget #{Shellwords.escape url}` elsif badass == :curl `curl -O #{Shellwords.escape url}` end end |
#cmd?(cmd) ⇒ Boolean
check if cmd available from system
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/getme/utilities.rb', line 22 def cmd?(cmd) exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| exts.each { |ext| exe = File.join(path, "#{cmd}#{ext}") return true if File.executable? exe } end return false end |
#downloader ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/getme/utilities.rb', line 11 def downloader if cmd?('wget') :wget elsif cmd?('curl') :curl else raise Getme::WgetOrCurlNotAvailableError, 'Wget or Curl not available for download files, install one? :D' end end |