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



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_osObject



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

Returns:

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

Returns:

  • (Boolean)


20
21
22
# File 'lib/travis/tools/system.rb', line 20

def linux?
  RUBY_PLATFORM =~ /linux/i
end

#mac?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/travis/tools/system.rb', line 16

def mac?
  RUBY_PLATFORM =~ /darwin/i
end

#osObject



28
29
30
# File 'lib/travis/tools/system.rb', line 28

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

#os_nameObject



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_typeObject



46
47
48
# File 'lib/travis/tools/system.rb', line 46

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

#os_versionObject



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

Returns:

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

#rubyObject



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_engineObject



50
51
52
# File 'lib/travis/tools/system.rb', line 50

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

#ruby_versionObject



54
55
56
# File 'lib/travis/tools/system.rb', line 54

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

#rubygemsObject



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

Returns:

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

Returns:

  • (Boolean)


24
25
26
# File 'lib/travis/tools/system.rb', line 24

def unix?
  not windows?
end

#windows?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/travis/tools/system.rb', line 12

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