Module: BBLib::OS

Defined in:
lib/bblib/core/util/os.rb

Class Method Summary collapse

Class Method Details

.linux?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/bblib/core/util/os.rb', line 14

def self.linux?
  !windows? && !mac?
end

.mac?Boolean

Returns:

  • (Boolean)


22
23
24
25
# File 'lib/bblib/core/util/os.rb', line 22

def self.mac?
  builds = ['darwin']
  !(/#{builds.join('|')}/i =~ RUBY_PLATFORM).nil?
end

.osObject



3
4
5
6
7
# 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?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/bblib/core/util/os.rb', line 18

def self.unix?
  !windows?
end

.which(cmd) ⇒ Object

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



28
29
30
31
32
33
34
35
36
# 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?Boolean

Returns:

  • (Boolean)


9
10
11
12
# 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