class SysLibDetector::Installer

Class responsible for installing the retrieved system libraries

Constants

AVAILABLE_OS

Available operating systems for installing the libraries are linux and macos only.

Public Class Methods

new() click to toggle source

Initializing the installer object with the current os

# File lib/sys_lib_detector/installer.rb, line 11
def initialize
        @os_name = get_os_name
end

Public Instance Methods

install(libraries) click to toggle source

Installing the required system libraries, packager specified according to the current operating system, showing info about the status of the libraries, whether installed or not @param libraries [Array] Retrieved required system libraries

# File lib/sys_lib_detector/installer.rb, line 19
def install(libraries)
        # Abort with a friendly message if the running OS is not supported yet
        abort "We're sorry but currently we don't support #{@os_name} package installation" if(!is_os_available?(@os_name))

        # Message shown handled by the displayer already
        abort if libraries.count == 0
        installed_libraries = []
        failed_libraries = []

        libraries.each do |library|
                installed = self.send("#{@os_name}_installer", library)
                if(installed == true)
                        installed_libraries << library
                else
                        failed_libraries << library
                end
        end

        if(failed_libraries.count > 0)
                abort "#{failed_libraries.count} libraries failed to be installed: #{failed_libraries}"
        else
                abort "#{installed_libraries.count} libraries installed successfully!"
        end
end

Private Instance Methods

get_os_name() click to toggle source

private method for getting the running operating system's name

# File lib/sys_lib_detector/installer.rb, line 46
def get_os_name
        return SystemDetector.get_os_name
end
is_os_available?(os_name) click to toggle source

private method for checking the availability of the operating system

# File lib/sys_lib_detector/installer.rb, line 51
def is_os_available?(os_name)
        return AVAILABLE_OS.include?(os_name)
end
linux_installer(package) click to toggle source

private method for running linux (apt) installing command

# File lib/sys_lib_detector/installer.rb, line 56
def linux_installer(package)
        system("sudo apt-get -y install #{package}")
end
osx_installer(package) click to toggle source

private method for running MacOS (homebrew) installing command

# File lib/sys_lib_detector/installer.rb, line 61
def osx_installer(package)
        system("brew install #{package}")
end