class Errors

Attributes

db[R]
dependency[R]
method[R]
param[R]
type[R]

Public Class Methods

custom_error(message) click to toggle source
# File lib/services.rb, line 69
def self.custom_error(message)
  begin
    raise Errors.invalid_param('message', 'String', 'Errors.custom_error') until message.is_a?(String)
  rescue => e
    e
  end

  puts("\n#{message}".colorize(:light_red))
end
invalid_param(param, type, method) click to toggle source
# File lib/services.rb, line 79
def self.invalid_param(param, type, method)
  begin
    raise Errors.invalid_param('param', 'String', 'Errors.invalid_param') until param.is_a?(String)
  rescue => e
    e
  end

  begin
    raise Errors.invalid_param('type', 'String', 'Errors.invalid_param') until type.is_a?(String)
  rescue => e
    e
  end

  begin
    raise Errors.invalid_param('method', 'String', 'Errors.invalid_param') until method.is_a?(String)
  rescue => e
    e
  end

  case type
  when 'String'
    puts "\n>> [RuntimeError] | #{param} must be an String on #{method}! \n   Your code won't work properly. Please rewrite your code and restart it.".colorize(:light_red)
  when 'Integer'
    puts "\n>> [RuntimeError] | #{param} must be an Integer on #{method}! \n   Your code won't work properly. Please rewrite your code and restart it.".colorize(:light_red)
  when 'Boolean'
    puts "\n>> [RuntimeError] | #{param} must be an Boolean on #{method}! \n   Your code won't work properly. Please rewrite your code and restart it.".colorize(:light_red)
  end
end
no_dependency(type, dependency) click to toggle source
# File lib/services.rb, line 23
def self.no_dependency(type, dependency)
  begin
    raise Errors.invalid_param('type', 'String', 'Errors.invalid_param') until type.is_a?(String)
  rescue => e
    e
  end

  begin
    raise Errors.invalid_param('dependency', 'String', 'Errors.invalid_param') until dependency.is_a?(String)
  rescue => e
    e
  end

  if system("#{dependency}") == nil
    puts "\n>> [RuntimeError] | The package #{dependency} isn't installed. \n   Do you want to install it? [y/n]".colorize(:light_red)
    installation = gets.chomp

    case installation
    when "y"
      if Dir.home == "/data/data/com.termux/files/home" # Termux installation
        if type.eql?('package')
          system("apt install #{dependency}")
        elsif type.eql?('gem')
          system("gem install #{dependency}")
        end
      else # Linux installation
        if File.exist?("/usr/bin/apt-get") then # Debian-based OS
          if type.eql?('package')
            system("sudo apt-get install #{dependency}")
          elsif type.eql?('gem')
            system("sudo gem install #{dependency}")
          end
        elsif File.exist?("/usr/bin/pacman") then # Arch OS
          if type.eql?('package')
            system("sudo pacman -S #{dependency}")
          elsif type.eql?('gem')
            system("sudo gem install #{dependency}")
          end
        end
      end
    when "n"
      puts "\n>> [RuntimeError] | You must install the dependencies so that the \n   administrator has a good functioning".colorize(:light_red)
    end
  end
end
protected_db(db, method) click to toggle source
# File lib/services.rb, line 108
def self.protected_db(db, method)
  begin
    raise Errors.invalid_param('db', 'String', 'Errors.protected_db') until db.is_a?(String)
  rescue => e
    e
  end

  begin
    raise Errors.invalid_param('method', 'String', 'Errors.protected_db') until method.is_a?(String)
  rescue => e
    e
  end

  case method
  when 'rename'
    puts "\n>> [SecurityError] | #{db}.rudb is protected! \n   If you want to rename it, you'll need to disable the Gembase protection.".colorize(:light_red)
  when 'delete'
    puts "\n>> [SecurityError] | #{db}.rudb is protected! \n   If you want to delete it, you'll need to disable the Gembase protection.".colorize(:light_red)
  when 'restart'
    puts "\n>> [SecurityError] | #{db}.rudb is protected! \n   If you want to restart it, you'll need to disable the Gembase protection.".colorize(:light_red)
  when 'encrypt'
    puts "\n>> [SecurityError] | #{db}.rudb isn't protected! \n   If you want to encrypt it, you'll need to enable the Gembase protection.".colorize(:light_red)
  end
end