Module: Travis::Tools::System
- Defined in:
- lib/travis/tools/system.rb
Class 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
Class Method Details
.description(*args) ⇒ Object
75 76 77 |
# File 'lib/travis/tools/system.rb', line 75 def description(*args) [full_os, ruby, rubygems, *args.flatten].compact.uniq.join('; ') end |
.full_os ⇒ Object
34 35 36 |
# File 'lib/travis/tools/system.rb', line 34 def full_os os_name == os_type ? os : "#{os} like #{os_type}" end |
.has?(command) ⇒ Boolean
79 80 81 82 83 84 |
# File 'lib/travis/tools/system.rb', line 79 def has?(command) return false unless unix? @has ||= {} @has.fetch(command) { @has[command] = system "command -v #{command} 2>/dev/null >/dev/null" } end |
.linux? ⇒ Boolean
22 23 24 |
# File 'lib/travis/tools/system.rb', line 22 def linux? RUBY_PLATFORM =~ /linux/i end |
.mac? ⇒ Boolean
18 19 20 |
# File 'lib/travis/tools/system.rb', line 18 def mac? RUBY_PLATFORM =~ /darwin/i end |
.os ⇒ Object
30 31 32 |
# File 'lib/travis/tools/system.rb', line 30 def os os_name ? "#{os_name} #{os_version}".strip : os_type end |
.os_name ⇒ Object
43 44 45 46 |
# File 'lib/travis/tools/system.rb', line 43 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
48 49 50 |
# File 'lib/travis/tools/system.rb', line 48 def os_type @os_type ||= windows? ? 'Windows' : `uname`.chomp end |
.os_version ⇒ Object
38 39 40 41 |
# File 'lib/travis/tools/system.rb', line 38 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
8 9 10 11 12 |
# File 'lib/travis/tools/system.rb', line 8 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
60 61 62 63 64 65 66 67 |
# File 'lib/travis/tools/system.rb', line 60 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
52 53 54 |
# File 'lib/travis/tools/system.rb', line 52 def ruby_engine defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby' end |
.ruby_version ⇒ Object
56 57 58 |
# File 'lib/travis/tools/system.rb', line 56 def ruby_version format('%s-p%s', RUBY_VERSION, RUBY_PATCHLEVEL) end |
.rubygems ⇒ Object
69 70 71 72 73 |
# File 'lib/travis/tools/system.rb', line 69 def rubygems return 'no RubyGems' unless defined? Gem "RubyGems #{Gem::VERSION}" end |
.running?(app) ⇒ Boolean
86 87 88 89 90 |
# File 'lib/travis/tools/system.rb', line 86 def running?(app) return false unless unix? system "/usr/bin/pgrep -u $(whoami) #{app} >/dev/null" end |
.unix? ⇒ Boolean
26 27 28 |
# File 'lib/travis/tools/system.rb', line 26 def unix? !windows? end |
.windows? ⇒ Boolean
14 15 16 |
# File 'lib/travis/tools/system.rb', line 14 def windows? File::ALT_SEPARATOR == '\\' end |