Module: CommandKit::OS

Extended by:
ModuleMethods
Included in:
OpenApp, PackageManager, Sudo
Defined in:
lib/command_kit/os.rb,
lib/command_kit/os/linux.rb

Overview

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

Defined Under Namespace

Modules: ClassMethods, Linux, ModuleMethods

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ModuleMethods

included

Instance Attribute Details

#os:linux, ... (readonly)

The current OS.

Returns:

  • (:linux, :macos, :freebsd, :openbsd, :netbsd, :windows, nil)

Since:

  • 0.2.0



82
83
84
# File 'lib/command_kit/os.rb', line 82

def os
  @os
end

Instance Method Details

#bsd?Boolean

Determines if the current OS is BSD based.

Returns:

  • (Boolean)

Since:

  • 0.2.0



173
174
175
# File 'lib/command_kit/os.rb', line 173

def bsd?
  freebsd? || openbsd? || netbsd?
end

#freebsd?Boolean

Determines if the current OS is FreeBSD.

Returns:

  • (Boolean)

Since:

  • 0.2.0



134
135
136
# File 'lib/command_kit/os.rb', line 134

def freebsd?
  @os == :freebsd
end

#initialize(os: self.class.os, **kwargs) ⇒ Object

Initializes the command.

Parameters:

  • os (:linux, :macos, :freebsd, :openbsd, :netbsd, :windows, nil) (defaults to: self.class.os)

    Overrides the default OS.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

Since:

  • 0.2.0



97
98
99
100
101
# File 'lib/command_kit/os.rb', line 97

def initialize(os: self.class.os, **kwargs)
  super(**kwargs)

  @os = os
end

#linux?Boolean

Determines if the current OS is Linux.

Returns:

  • (Boolean)


110
111
112
# File 'lib/command_kit/os.rb', line 110

def linux?
  @os == :linux
end

#macos?Boolean

Determines if the current OS is macOS.

Returns:

  • (Boolean)


121
122
123
# File 'lib/command_kit/os.rb', line 121

def macos?
  @os == :macos
end

#netbsd?Boolean

Determines if the current OS is NetBSD.

Returns:

  • (Boolean)

Since:

  • 0.2.0



160
161
162
# File 'lib/command_kit/os.rb', line 160

def netbsd?
  @os == :netbsd
end

#openbsd?Boolean

Determines if the current OS is OpenBSD.

Returns:

  • (Boolean)

Since:

  • 0.2.0



147
148
149
# File 'lib/command_kit/os.rb', line 147

def openbsd?
  @os == :openbsd
end

#unix?Boolean

Determines if the current OS is UNIX based.

Returns:

  • (Boolean)

Since:

  • 0.2.0



186
187
188
# File 'lib/command_kit/os.rb', line 186

def unix?
  linux? || macos? || bsd?
end

#windows?Boolean

Determines if the current OS is Windows.

Returns:

  • (Boolean)


197
198
199
# File 'lib/command_kit/os.rb', line 197

def windows?
  @os == :windows
end