error-handling 1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/error-handling.rb +82 -0
- metadata +46 -0
@@ -0,0 +1,82 @@
|
|
1
|
+
class Error
|
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 display_errors_ammount.kind_of? Integer
|
21
|
+
if $stored_errors.length > display_errors_ammount
|
22
|
+
#display error
|
23
|
+
print($stored_errors[display_errors_ammount - 1][0] + ": " + $stored_errors[display_errors_ammount - 1][1])
|
24
|
+
else
|
25
|
+
puts("Invalid error syntax, invalid error number.")
|
26
|
+
end
|
27
|
+
else
|
28
|
+
if display_errors_ammount == 'all'
|
29
|
+
|
30
|
+
#loop through and disply the errors
|
31
|
+
$stored_errors.each{ |indiviual_error|
|
32
|
+
puts("[" + indiviual_error[2].to_s + "] " + indiviual_error[0] + ": " + indiviual_error[1])
|
33
|
+
}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def count
|
39
|
+
#returns the amount of errors currently stored.
|
40
|
+
return $stored_errors.length
|
41
|
+
end
|
42
|
+
|
43
|
+
def export(errors_export_name)
|
44
|
+
|
45
|
+
#make sure 1 parameter is passed.
|
46
|
+
if !errors_export_name
|
47
|
+
puts("Invalid errors syntax, parameter expected \"filename\".")
|
48
|
+
end
|
49
|
+
|
50
|
+
#create error log file
|
51
|
+
File.open(errors_export_name, "w") do |file|
|
52
|
+
|
53
|
+
#loop through the errors putting them into the file
|
54
|
+
for i in 0..$stored_errors.length - 1
|
55
|
+
error_message = "[" + $stored_errors[i][2] + "] " + $stored_errors[i][0] + ": " + $stored_errors[i][1]
|
56
|
+
file.puts(error_message)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def erase(*include_check)
|
62
|
+
if include_check[0] == 'check'
|
63
|
+
#provides more control
|
64
|
+
print("You are about to erase your errors, would you like to continue? [Y/N]")
|
65
|
+
|
66
|
+
#loop to ensure y or n is entered.
|
67
|
+
while true
|
68
|
+
answer = gets.chop
|
69
|
+
if answer.upcase == 'Y'
|
70
|
+
$stored_errors.clear
|
71
|
+
break
|
72
|
+
elsif answer.upcase == 'N'
|
73
|
+
break
|
74
|
+
end
|
75
|
+
end
|
76
|
+
else
|
77
|
+
#clear errors without check
|
78
|
+
$stored_errors.clear
|
79
|
+
end
|
80
|
+
return
|
81
|
+
end
|
82
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: error-handling
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.1'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Peter Arnell
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-11-01 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Gem designed to improve error handling throughout your Ruby applications.
|
15
|
+
email:
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/error-handling.rb
|
21
|
+
homepage:
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 1.8.29
|
43
|
+
signing_key:
|
44
|
+
specification_version: 3
|
45
|
+
summary: Beautiful error handling.
|
46
|
+
test_files: []
|