Class: BloggerException
- Inherits:
-
Object
- Object
- BloggerException
- Defined in:
- lib/BloggerException.rb
Constant Summary collapse
- DESCRIPTIONS =
{ ZeroDivisionError: "Attempting to divide an Integer by 0.", NoMethodError: "A method is called on a receiver that does not have that method defined." }
Instance Attribute Summary collapse
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #display ⇒ Object
- #generate_description(type) ⇒ Object
-
#initialize ⇒ BloggerException
constructor
A new instance of BloggerException.
- #log ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ BloggerException
Returns a new instance of BloggerException.
2 3 4 5 6 7 8 9 10 11 12 |
# File 'lib/BloggerException.rb', line 2 def initialize @file = $0 @line = $!.backtrace[0].split(':')[1] @cause = $!.backtrace[0].split('`')[-1] = $!. @type = $!.class.to_s @description = generate_description(self.type.to_sym) @scope = $!.backtrace[0].split(/\./)[0] @time = Time.now.strftime("%I:%M:%S %p") @date = Time.now.strftime("%m/%d/%y") end |
Instance Attribute Details
#date ⇒ Object (readonly)
Returns the value of attribute date.
54 55 56 |
# File 'lib/BloggerException.rb', line 54 def date @date end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
54 55 56 |
# File 'lib/BloggerException.rb', line 54 def description @description end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
54 55 56 |
# File 'lib/BloggerException.rb', line 54 def file @file end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
54 55 56 |
# File 'lib/BloggerException.rb', line 54 def line @line end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
54 55 56 |
# File 'lib/BloggerException.rb', line 54 def time @time end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
54 55 56 |
# File 'lib/BloggerException.rb', line 54 def type @type end |
Instance Method Details
#display ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/BloggerException.rb', line 32 def display puts " \\tClass \#{self.type}\n \\tDescription: \#{self.description}\n \\tLine: \#{self.line}\n \\tTime: \#{self.time}\n \\tDate: \#{self.date}\n MLS\nend\n" |
#generate_description(type) ⇒ Object
49 50 51 52 |
# File 'lib/BloggerException.rb', line 49 def generate_description(type) return DESCRIPTIONS[type] if DESCRIPTIONS.key?(type) return 'Check out https://ruby-doc.org/core-2.7.0/Exception.html for more information.' end |
#log ⇒ Object
42 43 44 45 46 47 |
# File 'lib/BloggerException.rb', line 42 def log File.open('structured_exceptions.yml', 'a+') do |file| file.write (self.to_yaml) end puts 'Bug Logged Successfully:' end |
#to_s ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/BloggerException.rb', line 19 def to_s " :file: \#{file}\n :line: \#{line}\n :cause: \#{cause}\n :message: \#{message}\n :type: \#{type}\n :description \#{description}\n :scope: \#{scope}\n :time: \#{time}\n MLS\nend\n" |