Module: HostOS::Support

Included in:
HostOS
Defined in:
lib/host-os/support.rb

Overview

Note:

You need to require host-os/support explicitly.

This module provides helpful support methods for the HostOS module.

It adds attributes and methods depending on the detected operating system and Ruby interpreter.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dev_nullString (readonly)

Note:

This attribute is only available on Windows, OS2 and Unix systems for older Ruby versions.

Returns name of or path to the null device.

Returns:

  • (String)

    name of or path to the null device



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

def dev_null
  File::NULL
end

#open_commandString (readonly)

Note:

This attribute is only available on Windows, MacOS and Linux systems.

Returns name of the open command.

Returns:

  • (String)

    name of the open command



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

def open_command
  'start'
end

#rss_bytesInteger (readonly)

Note:

This attribute is only available on Windows and Unix or when using JRuby

Returns number of bytes used by the current process.

Returns:

  • (Integer)

    number of bytes used by the current process



57
58
59
60
61
62
# File 'lib/host-os/support.rb', line 57

def rss_bytes
  `tasklist /FI "PID eq #{Process.pid}" /FO CSV`.split(',"')[-1].tr(
    ',.',
    '__'
  ).to_i * 1024
end

#suggested_thread_countInteger (readonly)

Returns suggested number of threads to use.

Returns:

  • (Integer)

    suggested number of threads to use



101
102
103
# File 'lib/host-os/support.rb', line 101

def suggested_thread_count
  @suggested_thread_count ||= find_suggested_thread_count
end

#temp_dirString (readonly)

Returns name of the temporary directory.

Returns:

  • (String)

    name of the temporary directory



107
108
109
# File 'lib/host-os/support.rb', line 107

def temp_dir
  @temp_dir ||= find_temp_dir
end

Instance Method Details

#app_config_path(app_name) ⇒ String

Note:

This method is only available on Windows and Posix-compatible systems.

Determines the name of the directory where application specific data should be stored.

Parameters:

  • app_name (String)

    name of the application

Returns:

  • (String)

    absolute name of the directory



82
83
84
85
86
87
88
# File 'lib/host-os/support.rb', line 82

def app_config_path(app_name)
  File.expand_path(
    app_name,
    ENV['LOCALAPPDATA'] ||
      "#{ENV['USERPROFILE']}/Local Settings/Application Data"
  )
end