module Travis::Tools::System

Public Instance Methods

description(*args) click to toggle source
# File lib/travis/tools/system.rb, line 72
def description(*args)
  [ full_os, ruby, rubygems, *args.flatten].compact.uniq.join("; ")
end
full_os() click to toggle source
# File lib/travis/tools/system.rb, line 32
def full_os
  os_name == os_type ? os : "#{os} like #{os_type}"
end
has?(command) click to toggle source
# 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?() click to toggle source
# File lib/travis/tools/system.rb, line 20
def linux?
  RUBY_PLATFORM =~ /linux/i
end
mac?() click to toggle source
# File lib/travis/tools/system.rb, line 16
def mac?
  RUBY_PLATFORM =~ /darwin/i
end
os() click to toggle source
# File lib/travis/tools/system.rb, line 28
def os
  os_name ? "#{os_name} #{os_version}".strip : os_type
end
os_name() click to toggle source
# File lib/travis/tools/system.rb, line 41
def os_name
  @os_name ||= has?(:sw_vers)     && %x`sw_vers -productName`.chomp
  @os_name ||= has?(:lsb_release) && %x`lsb_release -i -s`.chomp
end
os_type() click to toggle source
# File lib/travis/tools/system.rb, line 46
def os_type
  @os_type ||= windows? ? 'Windows' : %x`uname`.chomp
end
os_version() click to toggle source
# File lib/travis/tools/system.rb, line 36
def os_version
  @os_version ||= has?(:sw_vers)     && %x`sw_vers -productVersion`.chomp
  @os_version ||= has?(:lsb_release) && %x`lsb_release -r -s`.chomp
end
recent_version?(version, minimum) click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/travis/tools/system.rb, line 50
def ruby_engine
  defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'
end
ruby_version() click to toggle source
# File lib/travis/tools/system.rb, line 54
def ruby_version
  "%s-p%s" % [RUBY_VERSION, RUBY_PATCHLEVEL]
end
rubygems() click to toggle source
# File lib/travis/tools/system.rb, line 67
def rubygems
  return "no RubyGems" unless defined? Gem
  "RubyGems #{Gem::VERSION}"
end
running?(app) click to toggle source
# File lib/travis/tools/system.rb, line 82
def running?(app)
  return false unless unix?
  system "pgrep -u $(whoami) #{app} >/dev/null"
end
unix?() click to toggle source
# File lib/travis/tools/system.rb, line 24
def unix?
  not windows?
end
windows?() click to toggle source
# File lib/travis/tools/system.rb, line 12
def windows?
  File::ALT_SEPARATOR == "\\"
end