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
- #recent_version?(version, minimum) ⇒ Boolean
- #ruby ⇒ Object
- #ruby_engine ⇒ Object
- #ruby_version ⇒ Object
- #rubygems ⇒ Object
- #running?(app) ⇒ Boolean
- #unix? ⇒ Boolean
- #windows? ⇒ Boolean
Instance Method Details
#description(*args) ⇒ Object
72 73 74 |
# File 'lib/travis/tools/system.rb', line 72 def description(*args) [ full_os, ruby, rubygems, *args.flatten].compact.uniq.join("; ") end |
#full_os ⇒ Object
32 33 34 |
# File 'lib/travis/tools/system.rb', line 32 def full_os os_name == os_type ? os : "#{os} like #{os_type}" end |
#has?(command) ⇒ Boolean
76 77 78 79 80 |
# File 'lib/travis/tools/system.rb', line 76 def has?(command) return false unless unix? @has ||= {} @has.fetch(command) { @has[command] = system "which #{command} 2>/dev/null >/dev/null" } end |
#linux? ⇒ Boolean
20 21 22 |
# File 'lib/travis/tools/system.rb', line 20 def linux? RUBY_PLATFORM =~ /linux/i end |
#mac? ⇒ Boolean
16 17 18 |
# File 'lib/travis/tools/system.rb', line 16 def mac? RUBY_PLATFORM =~ /darwin/i end |
#os ⇒ Object
28 29 30 |
# File 'lib/travis/tools/system.rb', line 28 def os os_name ? "#{os_name} #{os_version}".strip : os_type end |
#os_name ⇒ Object
41 42 43 44 |
# File 'lib/travis/tools/system.rb', line 41 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
46 47 48 |
# File 'lib/travis/tools/system.rb', line 46 def os_type @os_type ||= windows? ? 'Windows' : `uname`.chomp end |
#os_version ⇒ Object
36 37 38 39 |
# File 'lib/travis/tools/system.rb', line 36 def os_version @os_version ||= has?(:sw_vers) && `sw_vers -productVersion`.chomp @os_version ||= has?(:lsb_release) && `lsb_release -r -s`.chomp end |
#recent_version?(version, minimum) ⇒ Boolean
6 7 8 9 10 |
# File 'lib/travis/tools/system.rb', line 6 def recent_version?(version, minimum) version = version.split('.').map { |s| s.to_i } minimum = minimum.split('.').map { |s| s.to_i } (version <=> minimum) >= 0 end |
#ruby ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/travis/tools/system.rb', line 58 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
50 51 52 |
# File 'lib/travis/tools/system.rb', line 50 def ruby_engine defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby' end |
#ruby_version ⇒ Object
54 55 56 |
# File 'lib/travis/tools/system.rb', line 54 def ruby_version "%s-p%s" % [RUBY_VERSION, RUBY_PATCHLEVEL] end |
#rubygems ⇒ Object
67 68 69 70 |
# File 'lib/travis/tools/system.rb', line 67 def rubygems return "no RubyGems" unless defined? Gem "RubyGems #{Gem::VERSION}" end |
#running?(app) ⇒ Boolean
82 83 84 85 |
# File 'lib/travis/tools/system.rb', line 82 def running?(app) return false unless unix? system "pgrep -u $(whoami) #{app} >/dev/null" end |
#unix? ⇒ Boolean
24 25 26 |
# File 'lib/travis/tools/system.rb', line 24 def unix? not windows? end |
#windows? ⇒ Boolean
12 13 14 |
# File 'lib/travis/tools/system.rb', line 12 def windows? File::ALT_SEPARATOR == "\\" end |