
Security News
Researcher Exposes Zero-Day Clickjacking Vulnerabilities in Major Password Managers
Hacker Demonstrates How Easy It Is To Steal Data From Popular Password Managers
HostOS is a module that offers details about the host operating system, the current Ruby interpreter, and the environment currently in use.
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.
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.
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
Unknown package
We found that host-os demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Hacker Demonstrates How Easy It Is To Steal Data From Popular Password Managers
Security News
Oxlint’s new preview brings type-aware linting powered by typescript-go, combining advanced TypeScript rules with native-speed performance.
Security News
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.