Module: HostOS

Defined in:
lib/host-os.rb,
lib/host-os/support.rb,
lib/host-os/version.rb

Overview

HostOS is a module that provides information about the operating system, the current Ruby interpreter (HostOS.interpreter) and configured environment (HostOS.env). It helps you write environment-specific code in a clean way.

Defined Under Namespace

Modules: Env, Interpreter, Support

Constant Summary collapse

NAMES =
{
  bccwin: 'BCCWin',
  cygwin: 'Cygwin',
  dragonfly: 'Dragonly',
  freebsd: 'FreeBSD',
  linux: 'Linux',
  macosx: 'MacOSX',
  mingw: 'MinGW',
  mswin: 'MSWin',
  netbsd: 'NetBSD',
  openbsd: 'OpenBSD',
  sunos: 'SunOS',
  wince: 'WinCE',
  windows: 'Windows'
}.compare_by_identity.freeze
VERSION =

Returns the version number of the gem.

Returns:

  • (String)

    the version number of the gem

'0.2.0'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.cygwin?true, false (readonly)

Returns whether the host OS is Windows/Cygwin.

Returns:

  • (true, false)

    whether the host OS is Windows/Cygwin



274
275
276
# File 'lib/host-os.rb', line 274

def cygwin?
  ID == :cygwin
end

.envEnv (readonly)

Returns environment information.

Returns:

  • (Env)

    environment information



232
233
234
# File 'lib/host-os.rb', line 232

def env
  Env
end

.idSymbol (readonly)

Returns OS identifier.

Returns:

  • (Symbol)

    OS identifier



214
215
216
# File 'lib/host-os.rb', line 214

def id
  ID
end

.interpreterInterpreter (readonly)

Returns interpreter information.

Returns:



226
227
228
# File 'lib/host-os.rb', line 226

def interpreter
  Interpreter
end

.linux?true, false (readonly)

Returns whether the host OS is identified as Linux derivate.

Returns:

  • (true, false)

    whether the host OS is identified as Linux derivate



268
269
270
# File 'lib/host-os.rb', line 268

def linux?
  ID == :linux
end

.macosx?true, false (readonly)

Returns whether the host OS is identified as MacOS.

Returns:

  • (true, false)

    whether the host OS is identified as MacOS



262
263
264
# File 'lib/host-os.rb', line 262

def macosx?
  ID == :macosx
end

.os2?true, false (readonly)

Returns whether the host OS is OS/2.

Returns:

  • (true, false)

    whether the host OS is OS/2



256
257
258
# File 'lib/host-os.rb', line 256

def os2?
  TYPE == :os2
end

.posix?true, false (readonly)

This attribute is true when Posix compatible commands like fork are available.

Returns:

  • (true, false)

    whether the host OS is Posix compatible



282
283
284
# File 'lib/host-os.rb', line 282

def posix?
  Process.respond_to?(:fork)
end

.type:unix, ... (readonly)

Returns OS type.

Returns:

  • (:unix, :windows, :vms, :os2, :unknown)

    OS type



220
221
222
# File 'lib/host-os.rb', line 220

def type
  TYPE
end

.unix?true, false (readonly)

Returns whether the host OS is a Unix OS.

Returns:

  • (true, false)

    whether the host OS is a Unix OS



238
239
240
# File 'lib/host-os.rb', line 238

def unix?
  TYPE == :unix
end

.vms?true, false (readonly)

Returns whether the host OS is VMS.

Returns:

  • (true, false)

    whether the host OS is VMS



250
251
252
# File 'lib/host-os.rb', line 250

def vms?
  TYPE == :vms
end

.windows?true, false (readonly)

Returns whether the host OS is a Windows OS.

Returns:

  • (true, false)

    whether the host OS is a Windows OS



244
245
246
# File 'lib/host-os.rb', line 244

def windows?
  TYPE == :windows
end

Class Method Details

.is?(what) ⇒ true, false

Returns whether the host OS is the given identifier or type.

Parameters:

  • what (Symbol, String)

    the identifier to check

Returns:

  • (true, false)

    whether the host OS is the given identifier or type



288
289
290
291
292
# File 'lib/host-os.rb', line 288

def is?(what)
  return true if (ID == what) || (TYPE == what)
  what = defined?(what.to_sym) ? what.to_sym : what.to_s.to_sym
  (ID == what) || (TYPE == what)
end