class Uberinstaller::PackageManager::Base

Attributes

commands[R]

Public Class Methods

new() click to toggle source

Create the package manager

# File lib/uberinstaller/package_managers/base.rb, line 15
def initialize
  @commands = Hash.new
  @commands = {
    :add_repository => nil,
    :info => nil,
    :install => nil,
    :search => nil,
    :update => nil,
    :upgrade => nil
  }

  set_commands
end

Public Instance Methods

debug(action, args = []) click to toggle source

Print to log for debug purposes

@param action [String] the action that is being performed @param args [Array] an array of arguments for the specified action

# File lib/uberinstaller/package_managers/base.rb, line 40
def debug(action, args = [])
  logger.debug "action : #{action}"
  logger.debug "args   : #{args.join(', ')}" unless args.empty?
  logger.debug "command: #{make_command(action, args)}"
end
make_command(action, args = []) click to toggle source

Creates a command putting together action and arguments

@param action [String] the action that is being performed @param args [Array] an array of arguments for the specified action

# File lib/uberinstaller/package_managers/base.rb, line 50
def make_command(action, args = [])
  command = @commands[action.to_sym]
  command += " '" + args.join(' ') + "'" unless args.empty?

  command
end
method_missing(m, *args, &block) click to toggle source

All execution is handled dinamically via this function

If the method called is in the @commands Hash, the specified action is performed, otherwise a NoMethodError exception

@raise [NoMethodError] if the method specified is not available

# File lib/uberinstaller/package_managers/base.rb, line 63
def method_missing(m, *args, &block)
  if @commands.has_key? m
    debug m, args

    unless Config.dry_run
      Open3.popen3(make_command(m, args)) { |stdin, stdout, stderr, wait_thr|
        pid = wait_thr.pid # pid of the started process.
        logger.debug "Running pid: #{pid}"

        logger.debug stdout.readlines

        exit_status = wait_thr.value.to_i # Process::Status object returned.
        logger.debug "Exit status: #{exit_status}"
        logger.error 'Some error happended during execution:' unless exit_status == 0
        logger.error stderr.readlines unless exit_status == 0
      }
    end
  else
    raise NoMethodError
  end
end
set_commands() click to toggle source

This method is a stub, here only for reference

In every subclass of PackageManager::Base this method must be redefined specifying the package manager specific command ( see Apt and Dpkg for example )

# File lib/uberinstaller/package_managers/base.rb, line 34
def set_commands; end