Sha256: 2e59aa2a2f47aab0bc194f7591f90ebc4c7b891d0723b46f94d856edbd5eca5d

Contents?: true

Size: 968 Bytes

Versions: 6

Compression:

Stored size: 968 Bytes

Contents

module BBLib
  module OS
    def self.os
      return :windows if windows?
      return :mac if mac?
      return :linux if linux?
    end

    def self.windows?
      builds = %w(mingw mswin cygwin bccwin)
      !(/#{builds.join('|')}/i =~ RUBY_PLATFORM).nil?
    end

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

    def self.unix?
      !windows?
    end

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

    # Mostly platform agnost way to find the full path of an executable in the current env path.
    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
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
bblib-2.0.5 lib/bblib/core/util/os.rb
bblib-2.0.4 lib/bblib/core/util/os.rb
bblib-2.0.3 lib/bblib/core/util/os.rb
bblib-2.0.1 lib/bblib/core/util/os.rb
bblib-2.0.0 lib/bblib/core/util/os.rb
bblib-1.0.2 lib/os/bbos.rb