ruby_blogger 1.0.8 → 1.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/blog +0 -0
- data/lib/Blog.rb +101 -0
- data/lib/BloggerException.rb +60 -0
- data/lib/read_exceptions.rb +3 -128
- data/lib/ruby_blogger.rb +2 -32
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86e0f78c6ceff5429fc848afc12d678da8a596d02032925d1484bca1a11eedf8
|
4
|
+
data.tar.gz: 4e9655942941ed3b2bacbcee19af36a3394af76e523584f2ffdba639943023f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 702d42d9b17280ad6f99340a1419d5a73ee9a8380c57c576fe8af73c2702a0080eb8f5a53580d92cdc5c50c41ff2e3994e0c1953da94af0ae98ad33cfb183be0
|
7
|
+
data.tar.gz: 60432abdea74ed397af4d1870e92d6d811df072c5a4cab06c86e053a0d4439f5e1434b5ea15065a6413a808c01eaae173f7bd56ee695d41b047bf5c9786326b9
|
data/bin/blog
CHANGED
File without changes
|
data/lib/Blog.rb
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'yaml'
|
3
|
+
require_relative 'BloggerException.rb'
|
4
|
+
|
5
|
+
class Blog
|
6
|
+
attr_reader :exceptions,
|
7
|
+
:count_of_exceptions_in_folder,
|
8
|
+
:unique_files, :count_and_files,
|
9
|
+
:unique_exception_types, :specified_file
|
10
|
+
|
11
|
+
FILE = 'structured_exceptions.yml'
|
12
|
+
NO_EXCEPTIONS = "No exceptions have been raised by files that require 'ruby_blogger'"
|
13
|
+
|
14
|
+
def initialize(specified_file = nil)
|
15
|
+
@exceptions = YAML.load_stream(File.read(FILE))
|
16
|
+
@unique_files = exceptions.map { |exc| exc.file }.uniq
|
17
|
+
@count_and_files = "#{exceptions.length} in #{unique_files.join(' ')}"
|
18
|
+
@unique_exception_types = exceptions.map { |exc| exc.type }.uniq
|
19
|
+
@specified_file = specified_file
|
20
|
+
end
|
21
|
+
|
22
|
+
def count(type)
|
23
|
+
exceptions.select { |exc| exc.type == type }.length
|
24
|
+
end
|
25
|
+
|
26
|
+
def header
|
27
|
+
system('clear')
|
28
|
+
puts "Total Exceptions: #{count_and_files}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def folder_exceptions
|
32
|
+
unique_exception_types.each do |type|
|
33
|
+
puts "\n"
|
34
|
+
puts "Exception Class: #{type}"
|
35
|
+
puts "Total: #{self.count(type)}"
|
36
|
+
puts "-" * 15
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def display_summary
|
41
|
+
self.header
|
42
|
+
self.folder_exceptions
|
43
|
+
end
|
44
|
+
|
45
|
+
def read_exceptions_for_file(filename)
|
46
|
+
exceptions.select { |exc| exc.file == filename }
|
47
|
+
end
|
48
|
+
|
49
|
+
def display_exceptions_for_file(filename)
|
50
|
+
file_exceptions = read_exceptions_for_file(filename)
|
51
|
+
file_exceptions.each do |exc|
|
52
|
+
display_file_header(filename)
|
53
|
+
exc.display
|
54
|
+
end
|
55
|
+
display_file_trailer
|
56
|
+
end
|
57
|
+
|
58
|
+
def display_file_header(filename)
|
59
|
+
puts "\n"
|
60
|
+
puts "File: #{filename}"
|
61
|
+
puts '-' * 15
|
62
|
+
end
|
63
|
+
|
64
|
+
def display_file_trailer
|
65
|
+
puts '-' * 15
|
66
|
+
end
|
67
|
+
|
68
|
+
def display_file_does_not_exist(file)
|
69
|
+
puts "Sorry, #{file} is not a file in this folder."
|
70
|
+
end
|
71
|
+
|
72
|
+
def display_blog
|
73
|
+
if legit_file?(specified_file)
|
74
|
+
self.display_exceptions_for_file(specified_file)
|
75
|
+
elsif illegit_file?(specified_file)
|
76
|
+
self.display_file_does_not_exist(specified_file)
|
77
|
+
else
|
78
|
+
self.display_summary
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def legit_file?(file)
|
83
|
+
file && File.exist?(file)
|
84
|
+
end
|
85
|
+
|
86
|
+
def illegit_file?(file)
|
87
|
+
file && !File.exist?(file)
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.exceptions?
|
91
|
+
unless File.exist?(FILE)
|
92
|
+
puts NO_EXCEPTIONS
|
93
|
+
else return true
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.generate_and_display_blog
|
98
|
+
blog = self.new(ARGV[0])
|
99
|
+
blog.display_blog
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
class BloggerException
|
2
|
+
def initialize
|
3
|
+
@file = $0
|
4
|
+
@line = $!.backtrace[0].split(':')[1]
|
5
|
+
@cause = $!.backtrace[0].split('`')[-1]
|
6
|
+
@message = $!.message
|
7
|
+
@type = $!.class.to_s
|
8
|
+
@description = generate_description(self.type.to_sym)
|
9
|
+
@scope = $!.backtrace[0].split(/\./)[0]
|
10
|
+
@time = Time.now.strftime("%I:%M:%S %p")
|
11
|
+
@date = Time.now.strftime("%m/%d/%y")
|
12
|
+
end
|
13
|
+
|
14
|
+
DESCRIPTIONS = {
|
15
|
+
ZeroDivisionError: "Attempting to divide an Integer by 0.",
|
16
|
+
NoMethodError: "A method is called on a receiver that does not have that method defined."
|
17
|
+
}
|
18
|
+
|
19
|
+
def to_s
|
20
|
+
<<~MLS
|
21
|
+
:file: #{file}
|
22
|
+
:line: #{line}
|
23
|
+
:cause: #{cause}
|
24
|
+
:message: #{message}
|
25
|
+
:type: #{type}
|
26
|
+
:description #{description}
|
27
|
+
:scope: #{scope}
|
28
|
+
:time: #{time}
|
29
|
+
MLS
|
30
|
+
end
|
31
|
+
|
32
|
+
def display
|
33
|
+
puts <<~MLS
|
34
|
+
\tClass #{self.type}
|
35
|
+
\tDescription: #{self.description}
|
36
|
+
\tLine: #{self.line}
|
37
|
+
\tTime: #{self.time}
|
38
|
+
\tDate: #{self.date}
|
39
|
+
MLS
|
40
|
+
end
|
41
|
+
|
42
|
+
def log
|
43
|
+
File.open('structured_exceptions.yml', 'a+') do |file|
|
44
|
+
file.write (self.to_yaml)
|
45
|
+
end
|
46
|
+
puts 'Bug Logged Successfully:'
|
47
|
+
end
|
48
|
+
|
49
|
+
def generate_description(type)
|
50
|
+
return DESCRIPTIONS[type] if DESCRIPTIONS.key?(type)
|
51
|
+
return 'Check out https://ruby-doc.org/core-2.7.0/Exception.html for more information.'
|
52
|
+
end
|
53
|
+
|
54
|
+
attr_reader :file, :line, :type,
|
55
|
+
:description, :time, :date
|
56
|
+
private
|
57
|
+
attr_reader :cause,
|
58
|
+
:message,
|
59
|
+
:scope
|
60
|
+
end
|
data/lib/read_exceptions.rb
CHANGED
@@ -1,133 +1,8 @@
|
|
1
1
|
require 'bundler/setup'
|
2
2
|
require 'yaml'
|
3
|
-
|
4
|
-
|
5
|
-
exceptions = []
|
6
|
-
File.open('structured_exceptions.yml') do |yaml_file|
|
7
|
-
YAML.load_stream(yaml_file) do |yaml_doc|
|
8
|
-
exceptions << yaml_doc
|
9
|
-
end
|
10
|
-
end
|
11
|
-
exceptions
|
12
|
-
end
|
3
|
+
require_relative 'BloggerException.rb'
|
4
|
+
require_relative 'Blog.rb'
|
13
5
|
|
14
|
-
|
6
|
+
Blog.generate_and_display_blog if Blog.exceptions?
|
15
7
|
|
16
|
-
def get_total_project_exceptions_and_filenames(exceptions)
|
17
|
-
count = exceptions.length
|
18
|
-
filenames = get_all_filenames(exceptions)
|
19
|
-
"#{count} in #{filenames}"
|
20
|
-
end
|
21
8
|
|
22
|
-
def get_count_of_each_exception_class(exceptions)
|
23
|
-
counts = {}
|
24
|
-
exceptions.each do |exception|
|
25
|
-
type = exception[:type]
|
26
|
-
counts[type] ? counts[type] += 1 : counts[type] = 1
|
27
|
-
end
|
28
|
-
counts
|
29
|
-
end
|
30
|
-
|
31
|
-
#captures all filenames that require ruby_blogger that have raised exceptions
|
32
|
-
def get_all_filenames(exceptions)
|
33
|
-
exceptions.map { |exc| exc[:filename]}.uniq.join(', ')
|
34
|
-
end
|
35
|
-
|
36
|
-
#display count of total exceptions and each exception class and its count
|
37
|
-
def display_total_and_counts(total, counts)
|
38
|
-
system('clear')
|
39
|
-
puts "Total Exceptions: #{total}"
|
40
|
-
counts.each do |type, count|
|
41
|
-
puts "\n"
|
42
|
-
puts "Exception Class: #{type}"
|
43
|
-
puts "Total: #{count}"
|
44
|
-
puts "-" * 15
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
#combines all get methods to display all exceptions and counts raised by all files in the project folder
|
49
|
-
def display_summary
|
50
|
-
exceptions = read_all_exceptions
|
51
|
-
total = get_total_project_exceptions_and_filenames(exceptions)
|
52
|
-
counts = get_count_of_each_exception_class(exceptions)
|
53
|
-
display_total_and_counts(total, counts)
|
54
|
-
end
|
55
|
-
|
56
|
-
#These methods parse and display exception data for specified files
|
57
|
-
|
58
|
-
#get all exceptions for a given filename
|
59
|
-
def read_exceptions_for_file(filename)
|
60
|
-
exceptions = read_all_exceptions
|
61
|
-
exceptions.select do |exc|
|
62
|
-
exc[:filename] == filename
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
#display all exceptions and data for a given filename
|
67
|
-
def display_exceptions_for_file(filename)
|
68
|
-
display_header_info(filename)
|
69
|
-
display_each_exception(filename)
|
70
|
-
display_trailer
|
71
|
-
end
|
72
|
-
|
73
|
-
#passes each exception to format_exception_line and outputs each line
|
74
|
-
def display_each_exception(filename)
|
75
|
-
exceptions = read_exceptions_for_file(filename)
|
76
|
-
lines = exceptions.map do |exc|
|
77
|
-
format_exception_line(exc[:type],
|
78
|
-
exc[:description],
|
79
|
-
exc[:line_number],
|
80
|
-
exc[:time])
|
81
|
-
end
|
82
|
-
puts lines
|
83
|
-
end
|
84
|
-
|
85
|
-
#provide simple formatting for each exception class and line number
|
86
|
-
def format_exception_line(type, description, line, time)
|
87
|
-
date, time, tz = separate_date_and_time(time)
|
88
|
-
line_hash = { class: type,
|
89
|
-
description: description,
|
90
|
-
Line: line,
|
91
|
-
Time: time,
|
92
|
-
Date: date }
|
93
|
-
line_hash.map { |pair| pair.join(': ') }.join("\n ")
|
94
|
-
end
|
95
|
-
|
96
|
-
#separates date, time, and tz
|
97
|
-
def separate_date_and_time(time)
|
98
|
-
time.to_s.split(/\s/)
|
99
|
-
end
|
100
|
-
|
101
|
-
#display simple header in CL
|
102
|
-
def display_header_info(filename)
|
103
|
-
puts "\n"
|
104
|
-
puts "File: #{filename}"
|
105
|
-
puts '-' * 15
|
106
|
-
end
|
107
|
-
|
108
|
-
#display simple trailer in CL
|
109
|
-
def display_trailer
|
110
|
-
puts '-' * 15
|
111
|
-
end
|
112
|
-
|
113
|
-
#displays error message if user specifies non-existent file
|
114
|
-
def display_file_does_not_exist(file)
|
115
|
-
puts "Sorry, #{file} is not a file in this folder."
|
116
|
-
end
|
117
|
-
|
118
|
-
def display_no_exceptions
|
119
|
-
puts "No exceptions have been raised by files that require 'ruby_blogger'"
|
120
|
-
end
|
121
|
-
|
122
|
-
#functional logic to capture command line input and either display information for the file specified in the command line or display data for the entire folder if no file is specified.
|
123
|
-
specified_file = ARGV[0]
|
124
|
-
|
125
|
-
if !File.exist?('structured_exceptions.yml')
|
126
|
-
display_no_exceptions
|
127
|
-
elsif specified_file && File.exist?(specified_file)
|
128
|
-
display_exceptions_for_file(specified_file)
|
129
|
-
elsif specified_file && !File.exist?(specified_file)
|
130
|
-
display_file_does_not_exist(specified_file)
|
131
|
-
else
|
132
|
-
display_summary
|
133
|
-
end
|
data/lib/ruby_blogger.rb
CHANGED
@@ -1,39 +1,9 @@
|
|
1
1
|
require 'bundler/setup'
|
2
2
|
require 'yaml'
|
3
|
+
require_relative 'BloggerException.rb'
|
3
4
|
|
4
5
|
at_exit do
|
5
|
-
if $!
|
6
|
-
blogger = create_instance($!)
|
7
|
-
logging(blogger)
|
8
|
-
end
|
6
|
+
BloggerException.new.log if $!
|
9
7
|
end
|
10
8
|
|
11
|
-
def get_error_description(type)
|
12
|
-
errors = {
|
13
|
-
ZeroDivisionError: "Attempting to divide an Integer by 0.",
|
14
|
-
NoMethodError: "A method is called on a receiver that does not have that method defined."
|
15
|
-
}
|
16
9
|
|
17
|
-
return errors[type] if errors.key?(type)
|
18
|
-
return 'Check out https://ruby-doc.org/core-2.7.0/Exception.html for more information.' if !errors.key?(type)
|
19
|
-
end
|
20
|
-
|
21
|
-
def create_instance(exception)
|
22
|
-
blogger_entry = {}
|
23
|
-
blogger_entry[:filename] = $0
|
24
|
-
blogger_entry[:line_number] = $!.backtrace[0].split(':')[1]
|
25
|
-
blogger_entry[:cause] = $!.backtrace[0].split('`')[-1]
|
26
|
-
blogger_entry[:message] = $!.message
|
27
|
-
blogger_entry[:type] = $!.class.to_s
|
28
|
-
blogger_entry[:description] = get_error_description($!.class.to_s.to_sym)
|
29
|
-
blogger_entry[:scope] = self.to_s
|
30
|
-
blogger_entry[:time] = Time.now
|
31
|
-
blogger_entry
|
32
|
-
end
|
33
|
-
|
34
|
-
def logging(structured)
|
35
|
-
File.open('structured_exceptions.yml', 'a+') do |file|
|
36
|
-
file.write (structured.to_yaml)
|
37
|
-
end
|
38
|
-
puts 'Bug Logged Successfully:'
|
39
|
-
end
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_blogger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leena Lallmon
|
8
8
|
- Austin Miller
|
9
9
|
- Mandy Cheang
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2021-02-
|
13
|
+
date: 2021-02-15 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description: A command line developer tool to track exceptions
|
16
16
|
email:
|
@@ -22,13 +22,15 @@ extensions: []
|
|
22
22
|
extra_rdoc_files: []
|
23
23
|
files:
|
24
24
|
- bin/blog
|
25
|
+
- lib/Blog.rb
|
26
|
+
- lib/BloggerException.rb
|
25
27
|
- lib/read_exceptions.rb
|
26
28
|
- lib/ruby_blogger.rb
|
27
29
|
homepage: https://github.com/aumi9292/blogger
|
28
30
|
licenses:
|
29
31
|
- MIT
|
30
32
|
metadata: {}
|
31
|
-
post_install_message:
|
33
|
+
post_install_message:
|
32
34
|
rdoc_options: []
|
33
35
|
require_paths:
|
34
36
|
- lib
|
@@ -44,7 +46,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
44
46
|
version: '0'
|
45
47
|
requirements: []
|
46
48
|
rubygems_version: 3.1.2
|
47
|
-
signing_key:
|
49
|
+
signing_key:
|
48
50
|
specification_version: 4
|
49
51
|
summary: Capture and display data about exceptions your .rb file raises
|
50
52
|
test_files: []
|