module BBLib::OS

Public Class Methods

linux?() click to toggle source
# File lib/bblib/core/util/os.rb, line 14
def self.linux?
  !windows? && !mac?
end
mac?() click to toggle source
# File lib/bblib/core/util/os.rb, line 22
def self.mac?
  builds = ['darwin']
  !(/#{builds.join('|')}/i =~ RUBY_PLATFORM).nil?
end
os() click to toggle source
# File lib/bblib/core/util/os.rb, line 3
def self.os
  return :windows if windows?
  return :mac if mac?
  return :linux if linux?
end
unix?() click to toggle source
# File lib/bblib/core/util/os.rb, line 18
def self.unix?
  !windows?
end
which(cmd) click to toggle source

Mostly platform agnost way to find the full path of an executable in the current env path.

# File lib/bblib/core/util/os.rb, line 28
def self.which(cmd)
  ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
    (ENV['PATHEXT']&.split(';') || ['']).each do |ext|
      executable = File.join(path, "#{cmd}#{ext.downcase}").pathify
      return executable if File.executable?(executable) && !File.directory?(executable)
    end
  end
  nil
end
windows?() click to toggle source
# File lib/bblib/core/util/os.rb, line 9
def self.windows?
  builds = %w(mingw mswin cygwin bccwin)
  !(/#{builds.join('|')}/i =~ RUBY_PLATFORM).nil?
end