šŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →
Socket
Sign inDemoInstall
Socket

host-os

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

host-os

0.1.0
Rubygems
Version published
Maintainers
1
Created
Source

HostOS

version

HostOS is a module that offers details about the host operating system, the current Ruby interpreter, and the environment currently in use.

  • Gem: rubygems.org
  • Source: github.com
  • Help: rubydoc.info

Description

This gem helps you write environment-specific code in a clean way. It provides a simple API to get information about the operating system, the current Ruby interpreter, and the configured environment.

Usage

Here is a very simple example of OS dependent code:

require 'host-os'

if HostOS.unix?
  puts 'Hello Unix world!'
elsif HostOS.windows?
  puts 'Clean your Windows!'
elsif HostOS.os2? || HostOS.vms?
  puts 'Hello old school!'
end

You are free to write your code in whatever way you prefer. Here is a functionally identical but alternative to the example above:

require 'host-os'

if HostOS.is? :unix
  puts 'Hello Unix world!'
elsif HostOS.is? 'windows'
  puts 'Clean your Windows!'
elsif %i[os2 vms].include?(HostOS.type)
  puts 'Hello old school!'
end

The module also assists with environment- or interpreter-specific code:

require 'host-os'

Logger.log_level = HostOS.env.production? ? Logger::WARN : Logger::INFO
# => set the log level to 'WARN' in production, 'INFO' otherwise

require 'java' if HostOS.interpreter.jruby?
# => load the Java support for JRuby

There are additional methods that can support you on various platforms:

require 'host-os/support'

HostOS.dev_null
# => returns 'NUL' on Windows, 'nul' for OS2 and '/dev/null' on Unix platforms

HostOS.app_config_path('my_app')
# => returns the directory name where 'my_app' stores its configuration files

HostOS.rss_bytes
# => memory consumtion of current process in bytes
# means "total in memory footprint"

šŸ“• See the online help for more details.

Installation

This gem is compatible with Ruby 2.3 and higher. You can install it in your system with

gem install host-os

or you can use Bundler to add HostOS just to your own project:

bundle add 'host-os'

After that you only need one line of code to have everything together

require 'host-os'

FAQs

Package last updated on 30 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts