Module: Travis::Tools::System
Instance Method Summary collapse
- #description(*args) ⇒ Object
- #full_os ⇒ Object
- #has?(command) ⇒ Boolean
- #linux? ⇒ Boolean
- #mac? ⇒ Boolean
- #os ⇒ Object
- #os_name ⇒ Object
- #os_type ⇒ Object
- #os_version ⇒ Object
- #ruby ⇒ Object
- #ruby_engine ⇒ Object
- #ruby_version ⇒ Object
- #rubygems ⇒ Object
- #running?(app) ⇒ Boolean
- #unix? ⇒ Boolean
- #windows? ⇒ Boolean
Instance Method Details
#description(*args) ⇒ Object
66 67 68 |
# File 'lib/travis/tools/system.rb', line 66 def description(*args) [ full_os, ruby, rubygems, *args.flatten].compact.uniq.join("; ") end |
#full_os ⇒ Object
26 27 28 |
# File 'lib/travis/tools/system.rb', line 26 def full_os os_name == os_type ? os : "#{os} like #{os_type}" end |
#has?(command) ⇒ Boolean
70 71 72 73 74 |
# File 'lib/travis/tools/system.rb', line 70 def has?(command) return false unless unix? @has ||= {} @has.fetch(command) { @has[command] = system "which #{command} 2>/dev/null >/dev/null" } end |
#linux? ⇒ Boolean
14 15 16 |
# File 'lib/travis/tools/system.rb', line 14 def linux? RUBY_PLATFORM =~ /linux/i end |
#mac? ⇒ Boolean
10 11 12 |
# File 'lib/travis/tools/system.rb', line 10 def mac? RUBY_PLATFORM =~ /darwin/i end |
#os ⇒ Object
22 23 24 |
# File 'lib/travis/tools/system.rb', line 22 def os os_name ? "#{os_name} #{os_version}".strip : os_type end |
#os_name ⇒ Object
35 36 37 38 |
# File 'lib/travis/tools/system.rb', line 35 def os_name @os_name ||= has?(:sw_vers) && `sw_vers -productName`.chomp @os_name ||= has?(:lsb_release) && `lsb_release -i -s`.chomp end |
#os_type ⇒ Object
40 41 42 |
# File 'lib/travis/tools/system.rb', line 40 def os_type @os_type ||= windows? ? 'Windows' : `uname`.chomp end |
#os_version ⇒ Object
30 31 32 33 |
# File 'lib/travis/tools/system.rb', line 30 def os_version @os_version ||= has?(:sw_vers) && `sw_vers -productVersion`.chomp @os_version ||= has?(:lsb_release) && `lsb_release -r -s`.chomp end |
#ruby ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/travis/tools/system.rb', line 52 def ruby case ruby_engine when 'ruby' then "Ruby #{ruby_version}" when 'jruby' then "JRuby #{JRUBY_VERSION} like Ruby #{ruby_version}" when 'rbx' then "Rubinius #{Rubinius.version[/\d\S+/]} like Ruby #{ruby_version}" else "#{ruby_engine} like Ruby #{ruby_version}" end end |
#ruby_engine ⇒ Object
44 45 46 |
# File 'lib/travis/tools/system.rb', line 44 def ruby_engine defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby' end |
#ruby_version ⇒ Object
48 49 50 |
# File 'lib/travis/tools/system.rb', line 48 def ruby_version "%s-p%s" % [RUBY_VERSION, RUBY_PATCHLEVEL] end |
#rubygems ⇒ Object
61 62 63 64 |
# File 'lib/travis/tools/system.rb', line 61 def rubygems return "no RubyGems" unless defined? Gem "RubyGems #{Gem::VERSION}" end |
#running?(app) ⇒ Boolean
76 77 78 79 |
# File 'lib/travis/tools/system.rb', line 76 def running?(app) return false unless unix? system "pgrep -u $(whoami) #{app} >/dev/null" end |
#unix? ⇒ Boolean
18 19 20 |
# File 'lib/travis/tools/system.rb', line 18 def unix? not windows? end |
#windows? ⇒ Boolean
6 7 8 |
# File 'lib/travis/tools/system.rb', line 6 def windows? File::ALT_SEPARATOR == "\\" end |