error-handling 1.3 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/error-handling.rb +119 -119
- metadata +4 -2
data/lib/error-handling.rb
CHANGED
@@ -1,120 +1,120 @@
|
|
1
|
-
class ErrorHandling
|
2
|
-
#global errors array
|
3
|
-
$stored_errors = Array.new()
|
4
|
-
|
5
|
-
def create(*error_arguments)
|
6
|
-
if error_arguments.length == 2
|
7
|
-
#push new error to global errors array.
|
8
|
-
|
9
|
-
#get current date
|
10
|
-
time_date = Time.new
|
11
|
-
time = time_date.strftime('%Y-%m-%d')
|
12
|
-
$stored_errors.push([error_arguments[0], error_arguments[1], time])
|
13
|
-
else
|
14
|
-
#invalid number or parameters.
|
15
|
-
puts("Invalid error syntax, at least 2 parameters expected.")
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def display(display_errors_ammount)
|
20
|
-
if $stored_errors.length > 0
|
21
|
-
if display_errors_ammount.kind_of? Integer
|
22
|
-
if $stored_errors.length > display_errors_ammount
|
23
|
-
#display error
|
24
|
-
print($stored_errors[display_errors_ammount][0] + ": " + $stored_errors[display_errors_ammount][1])
|
25
|
-
else
|
26
|
-
puts("Invalid error syntax, invalid error number.")
|
27
|
-
end
|
28
|
-
elsif display_errors_ammount == 'last'
|
29
|
-
print($stored_errors[$stored_errors.length - 1][0] + ": " + $stored_errors[$stored_errors.length - 1][1])
|
30
|
-
|
31
|
-
else
|
32
|
-
if display_errors_ammount == 'all'
|
33
|
-
#loop through and disply the errors
|
34
|
-
$stored_errors.each{ |indiviual_error|
|
35
|
-
puts("[" + indiviual_error[2].to_s + "] " + indiviual_error[0] + ": " + indiviual_error[1])
|
36
|
-
}
|
37
|
-
end
|
38
|
-
end
|
39
|
-
else
|
40
|
-
puts("No errors are currently being stored,")
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def count
|
45
|
-
#returns the amount of errors currently stored.
|
46
|
-
return $stored_errors.length
|
47
|
-
end
|
48
|
-
|
49
|
-
def export(errors_export_name)
|
50
|
-
|
51
|
-
#make sure 1 parameter is passed.
|
52
|
-
if !errors_export_name
|
53
|
-
puts("Invalid errors syntax, parameter expected \"filename\".")
|
54
|
-
end
|
55
|
-
|
56
|
-
#create error log file
|
57
|
-
File.open(errors_export_name, "
|
58
|
-
|
59
|
-
#loop through the errors putting them into the file
|
60
|
-
for i in 0..$stored_errors.length - 1
|
61
|
-
error_message = "[" + $stored_errors[i][2] + "] " + $stored_errors[i][0] + ": " + $stored_errors[i][1]
|
62
|
-
file.puts(error_message)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def erase(*include_check)
|
68
|
-
if include_check[0] == 'check'
|
69
|
-
#provides more control
|
70
|
-
print("You are about to erase your errors, would you like to continue? [Y/N]")
|
71
|
-
|
72
|
-
#loop to ensure y or n is entered.
|
73
|
-
while true
|
74
|
-
answer = gets.chop
|
75
|
-
if answer.upcase == 'Y'
|
76
|
-
$stored_errors.clear
|
77
|
-
break
|
78
|
-
elsif answer.upcase == 'N'
|
79
|
-
break
|
80
|
-
end
|
81
|
-
end
|
82
|
-
else
|
83
|
-
#clear errors without check
|
84
|
-
$stored_errors.clear
|
85
|
-
end
|
86
|
-
return
|
87
|
-
end
|
88
|
-
|
89
|
-
def load(*load_file)
|
90
|
-
#varify the file does inface exist
|
91
|
-
if File.file?(load_file[0])
|
92
|
-
|
93
|
-
#open error file and read each line.
|
94
|
-
File.open(load_file[0], "r").each do |file_line|
|
95
|
-
|
96
|
-
#split the items to push individually into the errors array
|
97
|
-
error_split = file_line.split(" ")
|
98
|
-
|
99
|
-
#push errors into the $stored_errors array
|
100
|
-
$stored_errors.push([error_split[1].chop, error_split[2], error_split[0].slice(1..-1).chop])
|
101
|
-
|
102
|
-
#check for confirmation parameter
|
103
|
-
if load_file[1] and load_file[1] == 'confirm'
|
104
|
-
puts("External errors file loaded.")
|
105
|
-
end
|
106
|
-
|
107
|
-
end
|
108
|
-
else
|
109
|
-
puts("Load error: \"" + load_file[0] + "\" does not exist.")
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
def search(error_type)
|
114
|
-
$stored_errors.each{ |error|
|
115
|
-
if error[0] == error_type
|
116
|
-
puts("[" + error[2] + "] " + error[0] + ": " + error[1])
|
117
|
-
end
|
118
|
-
}
|
119
|
-
end
|
1
|
+
class ErrorHandling
|
2
|
+
#global errors array
|
3
|
+
$stored_errors = Array.new()
|
4
|
+
|
5
|
+
def create(*error_arguments)
|
6
|
+
if error_arguments.length == 2
|
7
|
+
#push new error to global errors array.
|
8
|
+
|
9
|
+
#get current date
|
10
|
+
time_date = Time.new
|
11
|
+
time = time_date.strftime('%Y-%m-%d')
|
12
|
+
$stored_errors.push([error_arguments[0], error_arguments[1], time])
|
13
|
+
else
|
14
|
+
#invalid number or parameters.
|
15
|
+
puts("Invalid error syntax, at least 2 parameters expected.")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def display(display_errors_ammount)
|
20
|
+
if $stored_errors.length > 0
|
21
|
+
if display_errors_ammount.kind_of? Integer
|
22
|
+
if $stored_errors.length > display_errors_ammount
|
23
|
+
#display error
|
24
|
+
print($stored_errors[display_errors_ammount][0] + ": " + $stored_errors[display_errors_ammount][1])
|
25
|
+
else
|
26
|
+
puts("Invalid error syntax, invalid error number.")
|
27
|
+
end
|
28
|
+
elsif display_errors_ammount == 'last'
|
29
|
+
print($stored_errors[$stored_errors.length - 1][0] + ": " + $stored_errors[$stored_errors.length - 1][1])
|
30
|
+
|
31
|
+
else
|
32
|
+
if display_errors_ammount == 'all'
|
33
|
+
#loop through and disply the errors
|
34
|
+
$stored_errors.each{ |indiviual_error|
|
35
|
+
puts("[" + indiviual_error[2].to_s + "] " + indiviual_error[0] + ": " + indiviual_error[1])
|
36
|
+
}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
else
|
40
|
+
puts("No errors are currently being stored,")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def count
|
45
|
+
#returns the amount of errors currently stored.
|
46
|
+
return $stored_errors.length
|
47
|
+
end
|
48
|
+
|
49
|
+
def export(errors_export_name)
|
50
|
+
|
51
|
+
#make sure 1 parameter is passed.
|
52
|
+
if !errors_export_name
|
53
|
+
puts("Invalid errors syntax, parameter expected \"filename\".")
|
54
|
+
end
|
55
|
+
|
56
|
+
#create error log file
|
57
|
+
File.open(errors_export_name, "a") do |file|
|
58
|
+
|
59
|
+
#loop through the errors putting them into the file
|
60
|
+
for i in 0..$stored_errors.length - 1
|
61
|
+
error_message = "[" + $stored_errors[i][2] + "] " + $stored_errors[i][0] + ": " + $stored_errors[i][1]
|
62
|
+
file.puts(error_message)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def erase(*include_check)
|
68
|
+
if include_check[0] == 'check'
|
69
|
+
#provides more control
|
70
|
+
print("You are about to erase your errors, would you like to continue? [Y/N]")
|
71
|
+
|
72
|
+
#loop to ensure y or n is entered.
|
73
|
+
while true
|
74
|
+
answer = gets.chop
|
75
|
+
if answer.upcase == 'Y'
|
76
|
+
$stored_errors.clear
|
77
|
+
break
|
78
|
+
elsif answer.upcase == 'N'
|
79
|
+
break
|
80
|
+
end
|
81
|
+
end
|
82
|
+
else
|
83
|
+
#clear errors without check
|
84
|
+
$stored_errors.clear
|
85
|
+
end
|
86
|
+
return
|
87
|
+
end
|
88
|
+
|
89
|
+
def load(*load_file)
|
90
|
+
#varify the file does inface exist
|
91
|
+
if File.file?(load_file[0])
|
92
|
+
|
93
|
+
#open error file and read each line.
|
94
|
+
File.open(load_file[0], "r").each do |file_line|
|
95
|
+
|
96
|
+
#split the items to push individually into the errors array
|
97
|
+
error_split = file_line.split(" ")
|
98
|
+
|
99
|
+
#push errors into the $stored_errors array
|
100
|
+
$stored_errors.push([error_split[1].chop, error_split[2], error_split[0].slice(1..-1).chop])
|
101
|
+
|
102
|
+
#check for confirmation parameter
|
103
|
+
if load_file[1] and load_file[1] == 'confirm'
|
104
|
+
puts("External errors file loaded.")
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
else
|
109
|
+
puts("Load error: \"" + load_file[0] + "\" does not exist.")
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def search(error_type)
|
114
|
+
$stored_errors.each{ |error|
|
115
|
+
if error[0] == error_type
|
116
|
+
puts("[" + error[2] + "] " + error[0] + ": " + error[1])
|
117
|
+
end
|
118
|
+
}
|
119
|
+
end
|
120
120
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: error-handling
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,9 @@ bindir: bin
|
|
11
11
|
cert_chain: []
|
12
12
|
date: 2015-01-24 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
|
-
description:
|
14
|
+
description: Error-Handling is a gem focused purly on improving how we handle errors
|
15
|
+
in our applications. Using a number of methods it allows you to create, export,
|
16
|
+
display and much more.
|
15
17
|
email:
|
16
18
|
executables: []
|
17
19
|
extensions: []
|