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 run(*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



84
85
86
# File 'lib/command_kit/os.rb', line 84

def os
  @os
end

Instance Method Details

#bsd?Boolean

Determines if the current OS is BSD based.

Returns:

  • (Boolean)

Since:

  • 0.2.0



175
176
177
# File 'lib/command_kit/os.rb', line 175

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

#freebsd?Boolean

Determines if the current OS is FreeBSD.

Returns:

  • (Boolean)

Since:

  • 0.2.0



136
137
138
# File 'lib/command_kit/os.rb', line 136

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



99
100
101
102
103
# File 'lib/command_kit/os.rb', line 99

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

  @os = os
end

#linux?Boolean

Determines if the current OS is Linux.

Returns:

  • (Boolean)


112
113
114
# File 'lib/command_kit/os.rb', line 112

def linux?
  @os == :linux
end

#macos?Boolean

Determines if the current OS is macOS.

Returns:

  • (Boolean)


123
124
125
# File 'lib/command_kit/os.rb', line 123

def macos?
  @os == :macos
end

#netbsd?Boolean

Determines if the current OS is NetBSD.

Returns:

  • (Boolean)

Since:

  • 0.2.0



162
163
164
# File 'lib/command_kit/os.rb', line 162

def netbsd?
  @os == :netbsd
end

#openbsd?Boolean

Determines if the current OS is OpenBSD.

Returns:

  • (Boolean)

Since:

  • 0.2.0



149
150
151
# File 'lib/command_kit/os.rb', line 149

def openbsd?
  @os == :openbsd
end

#unix?Boolean

Determines if the current OS is UNIX based.

Returns:

  • (Boolean)

Since:

  • 0.2.0



188
189
190
# File 'lib/command_kit/os.rb', line 188

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

#windows?Boolean

Determines if the current OS is Windows.

Returns:

  • (Boolean)


199
200
201
# File 'lib/command_kit/os.rb', line 199

def windows?
  @os == :windows
end