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

VERSION =

Returns the version number of the gem.

Returns:

  • (String)

    the version number of the gem

'0.1.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



279
280
281
# File 'lib/host-os.rb', line 279

def cygwin?
  ID == :cygwin
end

.envEnv (readonly)

Returns environment information.

Returns:

  • (Env)

    environment information



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

def env
  Env
end

.idSymbol (readonly)

Returns OS identifier.

Returns:

  • (Symbol)

    OS identifier



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

def id
  ID
end

.interpreterInterpreter (readonly)

Returns interpreter information.

Returns:



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

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



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

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



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

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



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

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



287
288
289
# File 'lib/host-os.rb', line 287

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

.type:unix, ... (readonly)

Returns OS type.

Returns:

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

    OS type



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

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



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

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



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

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



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

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



293
294
295
296
297
# File 'lib/host-os.rb', line 293

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