module CommandKit::OS
Provides methods for determining the current OS
.
## Examples
require 'command_kit/command' require 'command_kit/os' class Command < CommandKit::Command include CommandKit::OS def main(*argv) if linux? # ... elsif macos? # ... elsif freebsd? # ... elsif windows? # ... end end end
Attributes
The current OS
.
@return [:linux, :macos, :freebsd, :openbsd, :netbsd, :windows, nil]
@api public
@since 0.2.0
Public Class Methods
Initializes the command.
@param [:linux, :macos, :freebsd, :openbsd, :netbsd, :windows, nil] os
Overrides the default OS.
@param [Hash{Symbol => Object}] kwargs
Additional keyword arguments.
@api public
@since 0.2.0
# File lib/command_kit/os.rb, line 97 def initialize(os: self.class.os, **kwargs) super(**kwargs) @os = os end
Public Instance Methods
Determines if the current OS
is BSD based.
@return [Boolean]
@since 0.2.0
@api public
# File lib/command_kit/os.rb, line 173 def bsd? freebsd? || openbsd? || netbsd? end
Determines if the current OS
is FreeBSD.
@return [Boolean]
@api public
@since 0.2.0
# File lib/command_kit/os.rb, line 134 def freebsd? @os == :freebsd end
Determines if the current OS
is macOS.
@return [Boolean]
@api public
# File lib/command_kit/os.rb, line 121 def macos? @os == :macos end
Determines if the current OS
is NetBSD.
@return [Boolean]
@api public
@since 0.2.0
# File lib/command_kit/os.rb, line 160 def netbsd? @os == :netbsd end
Determines if the current OS
is OpenBSD.
@return [Boolean]
@api public
@since 0.2.0
# File lib/command_kit/os.rb, line 147 def openbsd? @os == :openbsd end
Determines if the current OS
is UNIX based.
@return [Boolean]
@since 0.2.0
@api public
# File lib/command_kit/os.rb, line 186 def unix? linux? || macos? || bsd? end
Determines if the current OS
is Windows.
@return [Boolean]
@api public
# File lib/command_kit/os.rb, line 197 def windows? @os == :windows end