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

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



63
64
65
# File 'lib/host-os.rb', line 63

def cygwin?
  @id == :cygwin
end

.envEnv (readonly)

Returns environment information.

Returns:

  • (Env)

    environment information



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

def env
  Env
end

.idSymbol (readonly)

Returns OS identifier.

Returns:

  • (Symbol)

    OS identifier



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


.interpreterInterpreter (readonly)

Returns interpreter information.

Returns:



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

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



57
58
59
# File 'lib/host-os.rb', line 57

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



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

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



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

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



71
72
73
# File 'lib/host-os.rb', line 71

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

.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



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

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



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

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



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

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



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/host-os.rb', line 77

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