ruby_blogger 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8fd3a46556c69d047b2a20d43a11f07501d7ff1ff539bc0c5e635e2fe3fe45ca
4
+ data.tar.gz: 459c0ebd7e8b0c011f10eba29e9163b83c967c997eb03b9cab6cf74c7c3209da
5
+ SHA512:
6
+ metadata.gz: 8a7481dacfc48a8ff5bfbaeb6ed528d7629a7a47549b781403793b0c4421f024bf58bf65a2606e8312a4bf44f7ead50bfed1fd92fc2369b1d34b821b8b02dc1b
7
+ data.tar.gz: ce6a6a7427cdf5411022e207fa2facd3221d2626bc57d56cdeb04ee741c6a361384ad5d648ccd8c62613223793b031d9d8a3650b8db717efd6e129d3d810f00c
data/bin/blog ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'read_exceptions'
@@ -0,0 +1,115 @@
1
+ require 'bundler/setup'
2
+ require 'yaml'
3
+ #opens the .yml file, which is an IO object, passes it to YAML.load_streams. In the block, yaml_doc represents each exception in the .yml file
4
+ def read_all_exceptions
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
13
+
14
+ #The following grouping of methods parse and display exception data for the whole project folder
15
+
16
+ def get_total_project_exceptions(exceptions)
17
+ exceptions.length
18
+ end
19
+
20
+ def get_count_of_each_exception_class(exceptions)
21
+ counts = {}
22
+ exceptions.each do |exception|
23
+ type = exception[:type]
24
+ counts[type] ? counts[type] += 1 : counts[type] = 1
25
+ end
26
+ counts
27
+ end
28
+
29
+ #display count of total exceptions and each exception class and its count
30
+ def display_total_and_counts(total, counts)
31
+ system('clear')
32
+ puts "Total Exceptions: #{total}"
33
+ counts.each do |type, count|
34
+ puts "\n"
35
+ puts "Exception Class: #{type}"
36
+ puts "Total: #{count}"
37
+ puts "-" * 80
38
+ end
39
+ end
40
+
41
+ #combines all get methods to display all exceptions and counts raised by all files in the project folder
42
+ def display_summary
43
+ exceptions = read_all_exceptions
44
+ total = get_total_project_exceptions(exceptions)
45
+ counts = get_count_of_each_exception_class(exceptions)
46
+ display_total_and_counts(total, counts)
47
+ end
48
+
49
+ #These methods parse and display exception data for specified files
50
+
51
+ #get all exceptions for a given filename
52
+ def read_exceptions_for_file(filename)
53
+ exceptions = read_all_exceptions
54
+ exceptions.select do |exc|
55
+ exc[:filename] == filename
56
+ end
57
+ end
58
+
59
+ #display all exceptions and data for a given filename
60
+ def display_exceptions_for_file(filename)
61
+ display_header_info(filename)
62
+ display_each_exception(filename)
63
+ display_trailer
64
+ end
65
+
66
+ #passes each exception to format_exception_line and outputs each line
67
+ def display_each_exception(filename)
68
+ exceptions = read_exceptions_for_file(filename)
69
+ lines = exceptions.map do |exc|
70
+ format_exception_line(exc[:type],
71
+ exc[:line_number],
72
+ exc[:time])
73
+ end
74
+ puts lines
75
+ end
76
+
77
+ #provide simple formatting for each exception class and line number
78
+ def format_exception_line(type, line, time)
79
+ date, time, tz = separate_date_and_time(time)
80
+ l_hash = { class: type, Line: line, Time: time, Date: date }
81
+ l_hash.map { |pair| pair.join(': ') }.join(' ')
82
+ end
83
+
84
+ #separates date, time, and tz
85
+ def separate_date_and_time(time)
86
+ time.to_s.split(/\s/)
87
+ end
88
+
89
+ #display simple header in CL
90
+ def display_header_info(filename)
91
+ puts "\n"
92
+ puts "File: #{filename}"
93
+ puts '-' * 80
94
+ end
95
+
96
+ #display simple trailer in CL
97
+ def display_trailer
98
+ puts '-' * 80
99
+ end
100
+
101
+ #displays error message if user specifies non-existent file
102
+ def display_file_does_not_exist(file)
103
+ puts "Sorry, #{file} is not a file in this folder."
104
+ end
105
+
106
+ #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.
107
+ specified_file = ARGV[0]
108
+
109
+ if specified_file && File.exist?(specified_file)
110
+ display_exceptions_for_file(specified_file)
111
+ elsif specified_file && !File.exist?(specified_file)
112
+ display_file_does_not_exist(specified_file)
113
+ else
114
+ display_summary
115
+ end
@@ -0,0 +1,28 @@
1
+ require 'bundler/setup'
2
+ require 'yaml'
3
+
4
+ at_exit do
5
+ if $!
6
+ blogger = create_instance($!)
7
+ logging(blogger)
8
+ end
9
+ end
10
+
11
+ def create_instance(exception)
12
+ blogger_entry = {}
13
+ blogger_entry[:filename] = $0
14
+ blogger_entry[:line_number] = $!.backtrace[0].split(':')[1]
15
+ blogger_entry[:cause] = $!.backtrace[0].split('`')[-1]
16
+ blogger_entry[:message] = $!.message
17
+ blogger_entry[:type] = $!.class.to_s
18
+ blogger_entry[:scope] = self.to_s
19
+ blogger_entry[:time] = Time.now
20
+ puts 'Entry logged successfully'
21
+ blogger_entry
22
+ end
23
+
24
+ def logging(structured)
25
+ File.open('structured_exceptions.yml', 'a+') do |file|
26
+ file.write (structured.to_yaml)
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby_blogger
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.5
5
+ platform: ruby
6
+ authors:
7
+ - Leena Lallmon
8
+ - Austin Miller
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2021-02-05 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A command line developer tool to track exceptions
15
+ email:
16
+ - austin.miller@colorado.edu
17
+ - leena.lallmon@gmail.com
18
+ executables:
19
+ - blog
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - bin/blog
24
+ - lib/read_exceptions.rb
25
+ - lib/ruby_blogger.rb
26
+ homepage: https://github.com/aumi9292/blogger
27
+ licenses:
28
+ - MIT
29
+ metadata: {}
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubygems_version: 3.1.2
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: Capture and display data about exceptions your .rb file raises
49
+ test_files: []