Exception: Errors

Inherits:
StandardError
  • Object
show all
Defined in:
lib/services.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#dbObject (readonly)

Returns the value of attribute db.



21
22
23
# File 'lib/services.rb', line 21

def db
  @db
end

#dependencyObject (readonly)

Returns the value of attribute dependency.



21
22
23
# File 'lib/services.rb', line 21

def dependency
  @dependency
end

#methodObject (readonly)

Returns the value of attribute method.



21
22
23
# File 'lib/services.rb', line 21

def method
  @method
end

#paramObject (readonly)

Returns the value of attribute param.



21
22
23
# File 'lib/services.rb', line 21

def param
  @param
end

#typeObject (readonly)

Returns the value of attribute type.



21
22
23
# File 'lib/services.rb', line 21

def type
  @type
end

Class Method Details

.custom_error(message) ⇒ Object



69
70
71
72
73
74
75
76
77
# 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) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# 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) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# 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) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# 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