Module: HostOS

Extended by:
Support
Defined in:
lib/host-os.rb,
lib/host-os/support.rb,
lib/host-os/version.rb,
lib/host-os/interpreter.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 =

Version number of the gem.

'0.4.0'

Class Attribute Summary collapse

Attributes included from Support

#dev_null, #open_command, #rss_bytes, #suggested_thread_count, #temp_dir

Class Method Summary collapse

Methods included from Support

app_config_path

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



47
# File 'lib/host-os.rb', line 47

def cygwin? = (@id == :cygwin)

.envEnv (readonly)

Returns environment information.

Returns:

  • (Env)

    environment information



19
# File 'lib/host-os.rb', line 19

def env = Env

.idSymbol (readonly)

Returns OS identifier.

Returns:

  • (Symbol)

    OS identifier



# File 'lib/host-os.rb', line 70

.interpreterInterpreter (readonly)

Returns interpreter information.

Returns:



15
# File 'lib/host-os.rb', line 15

def interpreter = Interpreter

.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



43
# File 'lib/host-os.rb', line 43

def linux? = (@id == :linux)

.macosx?true, false (readonly)

Returns whether the host OS is identified as MacOS.

Returns:

  • (true, false)

    whether the host OS is identified as MacOS



39
# File 'lib/host-os.rb', line 39

def macosx? = (@id == :macosx)

.os2?true, false (readonly)

Returns whether the host OS is OS/2.

Returns:

  • (true, false)

    whether the host OS is OS/2



35
# File 'lib/host-os.rb', line 35

def os2? = (@type == :os2)

.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



53
# File 'lib/host-os.rb', line 53

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

.type:unix, ... (readonly)

Returns OS type.

Returns:

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

    OS type



11
12
13
# File 'lib/host-os.rb', line 11

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



23
# File 'lib/host-os.rb', line 23

def unix? = (@type == :unix)

.vms?true, false (readonly)

Returns whether the host OS is VMS.

Returns:

  • (true, false)

    whether the host OS is VMS



31
# File 'lib/host-os.rb', line 31

def vms? = (@type == :vms)

.windows?true, false (readonly)

Returns whether the host OS is a Windows OS.

Returns:

  • (true, false)

    whether the host OS is a Windows OS



27
# File 'lib/host-os.rb', line 27

def windows? = (@type == :windows)

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



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/host-os.rb', line 57

def is?(what)
  return (@id == what) || (@type == what) if what.is_a?(Symbol)
  if defined?(what.to_sym)
    what = what.to_sym
    return (@id == what) || (@type == what)
  end
  if defined?(what.to_s)
    what = what.to_s.to_sym
    return (@id == what) || (@type == what)
  end
  false
end