Module: Travis::Tools::System

Extended by:
System
Included in:
System
Defined in:
lib/travis/tools/system.rb

Instance Method Summary collapse

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_osObject



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

Returns:

  • (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

Returns:

  • (Boolean)


14
15
16
# File 'lib/travis/tools/system.rb', line 14

def linux?
  RUBY_PLATFORM =~ /linux/i
end

#mac?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/travis/tools/system.rb', line 10

def mac?
  RUBY_PLATFORM =~ /darwin/i
end

#osObject



22
23
24
# File 'lib/travis/tools/system.rb', line 22

def os
  os_name ? "#{os_name} #{os_version}".strip : os_type
end

#os_nameObject



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_typeObject



40
41
42
# File 'lib/travis/tools/system.rb', line 40

def os_type
  @os_type ||= windows? ? 'Windows' : `uname`.chomp
end

#os_versionObject



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

#rubyObject



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_engineObject



44
45
46
# File 'lib/travis/tools/system.rb', line 44

def ruby_engine
  defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'
end

#ruby_versionObject



48
49
50
# File 'lib/travis/tools/system.rb', line 48

def ruby_version
  "%s-p%s" % [RUBY_VERSION, RUBY_PATCHLEVEL]
end

#rubygemsObject



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

Returns:

  • (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

Returns:

  • (Boolean)


18
19
20
# File 'lib/travis/tools/system.rb', line 18

def unix?
  not windows?
end

#windows?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/travis/tools/system.rb', line 6

def windows?
  File::ALT_SEPARATOR == "\\"
end