error-handling 1.3.1 → 1.4

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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/error-handling.rb +74 -83
  3. metadata +12 -14
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3d44623e084cd094bfa3f041a6c63f99fb25d008
4
+ data.tar.gz: fc90699627960da26270bb1e3257bdb165a72c15
5
+ SHA512:
6
+ metadata.gz: 078c961222e1571c63cb87b5a34e0a54f16c3a77672d75795c5e010ff546318e35f427516e2b000b398ee300f64cd44df72282b6eab508374be02cb6ae2a5237
7
+ data.tar.gz: 940d24e50df97690dd7c586af7e753ee1c3d278d4f319b042b7b1ecf3ddba6b7975be35f67e61983e2bc72a0cfbec94b52557a610e6fd7324493f01605978544
@@ -1,90 +1,85 @@
1
1
  class ErrorHandling
2
- #global errors array
3
- $stored_errors = Array.new()
4
2
 
5
- def create(*error_arguments)
6
- if error_arguments.length == 2
7
- #push new error to global errors array.
3
+ $stored_errors = Array.new()
8
4
 
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
5
+ def create(*error_arguments)
6
+
7
+ return "Invalid error syntax, at least 2 parameters expected" if error_arguments.length != 2
8
+
9
+ #get current date
10
+ time = Time.new.strftime('%Y-%m-%d')
11
+ #store error
12
+ $stored_errors.push([error_arguments[0], error_arguments[1], time])
13
+ end
14
+
15
+ def display(display_errors_ammount)
16
+
17
+ #make sure errors are being stored
18
+ return puts "No errors are currently being stored." if $stored_errors.length < 0
18
19
 
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
20
+ #check data type
21
+ if display_errors_ammount.kind_of? Integer
22
+
23
+ return "Invalid error syntax, bad error number." if $stored_errors.length < display_errors_ammount
24
+
25
+ puts "[#{$stored_errors[display_errors_ammount][2]}] #{$stored_errors[display_errors_ammount][0]}: #{$stored_errors[display_errors_ammount][1]}"
26
+
27
+ elsif display_errors_ammount == 'last'
28
+
29
+ puts "[#{$stored_errors[$stored_errors.length - 1][2]}] #{$stored_errors[$stored_errors.length - 1][0]}: #{$stored_errors[$stored_errors.length - 1][1]}"
30
+
31
+ else
32
+
33
+ if display_errors_ammount == 'all'
34
+ #loop through and disply the errors
35
+ $stored_errors.each{ |indiviual_error|
36
+ puts "[#{indiviual_error[2]}] #{indiviual_error[0]}: #{indiviual_error[1]}"
37
+ }
38
38
  end
39
- else
40
- puts("No errors are currently being stored,")
41
- end
42
- end
39
+ end
40
+ end
43
41
 
44
- def count
45
- #returns the amount of errors currently stored.
46
- return $stored_errors.length
47
- end
42
+ def count
43
+ return $stored_errors.length
44
+ end
48
45
 
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
46
+ def export(errors_export_name)
55
47
 
56
- #create error log file
57
- File.open(errors_export_name, "a") do |file|
48
+ #make sure filename is a string
49
+ puts "Invalid errors syntax, parameter passed must be a string." if !errors_export_name.kind_of? String
58
50
 
59
- #loop through the errors putting them into the file
51
+ #create error log file
52
+ File.open(errors_export_name, "a") do |file|
53
+
54
+ #loop through the errors putting them into the file
60
55
  for i in 0..$stored_errors.length - 1
61
- error_message = "[" + $stored_errors[i][2] + "] " + $stored_errors[i][0] + ": " + $stored_errors[i][1]
56
+ error_message = "[#{$stored_errors[i][2]}] #{$stored_errors[i][0]}: #{$stored_errors[i][1]}"
62
57
  file.puts(error_message)
63
58
  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
59
+ end
60
+ end
61
+
62
+ def erase(*include_check)
63
+
64
+ if include_check[0] == 'check'
65
+ #loop to ensure y or n is entered.
66
+ loop do
67
+ print("You are about to erase your errors, would you like to continue? [Y/N]")
68
+ answer = gets.chop.upcase
69
+
70
+ case answer
71
+ when 'Y' then
72
+ $stored_errors.clear
73
+ break
74
+ when 'N' then break
75
+ else puts "Invalid answer, try again."
76
+ end
77
+ end
78
+ else
79
+ #clear errors without check
80
+ $stored_errors.clear
81
+ end
82
+ end
88
83
 
89
84
  def load(*load_file)
90
85
  #varify the file does inface exist
@@ -100,21 +95,17 @@ class ErrorHandling
100
95
  $stored_errors.push([error_split[1].chop, error_split[2], error_split[0].slice(1..-1).chop])
101
96
 
102
97
  #check for confirmation parameter
103
- if load_file[1] and load_file[1] == 'confirm'
104
- puts("External errors file loaded.")
105
- end
98
+ puts "External errors file loaded." if load_file[1] == 'confirm'
106
99
 
107
100
  end
108
101
  else
109
- puts("Load error: \"" + load_file[0] + "\" does not exist.")
102
+ return "Load error: \"#{load_file[0]}\" does not exist."
110
103
  end
111
104
  end
112
105
 
113
106
  def search(error_type)
114
107
  $stored_errors.each{ |error|
115
- if error[0] == error_type
116
- puts("[" + error[2] + "] " + error[0] + ": " + error[1])
117
- end
108
+ puts "[" + error[2] + "] " + error[0] + ": " + error[1] if error[0] == error_type
118
109
  }
119
110
  end
120
- end
111
+ end
metadata CHANGED
@@ -1,48 +1,46 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: error-handling
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
5
- prerelease:
4
+ version: '1.4'
6
5
  platform: ruby
7
6
  authors:
8
7
  - Peter Arnell
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2015-01-24 00:00:00.000000000 Z
11
+ date: 2016-02-12 00:00:00.000000000 Z
13
12
  dependencies: []
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.
13
+ description: Error-Handling is a gem focused on improving how we handle errors in
14
+ our applications. Using a number of methods it allows you to create, export, display
15
+ and much more.
17
16
  email:
18
17
  executables: []
19
18
  extensions: []
20
19
  extra_rdoc_files: []
21
20
  files:
22
21
  - lib/error-handling.rb
23
- homepage: https://github.com/mrpteo/Error-Handling
22
+ homepage: https://github.com/tophbeifong/Error-Handling/
24
23
  licenses:
25
24
  - MIT
25
+ metadata: {}
26
26
  post_install_message:
27
27
  rdoc_options: []
28
28
  require_paths:
29
29
  - lib
30
30
  required_ruby_version: !ruby/object:Gem::Requirement
31
- none: false
32
31
  requirements:
33
- - - ! '>='
32
+ - - ">="
34
33
  - !ruby/object:Gem::Version
35
34
  version: '0'
36
35
  required_rubygems_version: !ruby/object:Gem::Requirement
37
- none: false
38
36
  requirements:
39
- - - ! '>='
37
+ - - ">="
40
38
  - !ruby/object:Gem::Version
41
39
  version: '0'
42
40
  requirements: []
43
41
  rubyforge_project:
44
- rubygems_version: 1.8.28
42
+ rubygems_version: 2.4.5.1
45
43
  signing_key:
46
- specification_version: 3
47
- summary: Beautiful solution to error handling.
44
+ specification_version: 4
45
+ summary: Beautiful solution to application error handling.
48
46
  test_files: []