Class: Debug
- Inherits:
-
Object
- Object
- Debug
- Defined in:
- lib/tiny_grabber/debug.rb
Overview
Save debug log information
Instance Attribute Summary collapse
-
#active ⇒ Object
Get debug active flag.
-
#destination ⇒ Object
Get debug destination.
-
#save_html ⇒ Object
Get debug flag to save response HTML to file.
Instance Method Summary collapse
-
#initialize ⇒ Debug
constructor
Initialize a debug object.
-
#save(message) ⇒ Object
Save log information.
-
#save_to_file(message) ⇒ Object
Save log information to file.
Constructor Details
#initialize ⇒ Debug
Initialize a debug object
12 13 14 15 16 |
# File 'lib/tiny_grabber/debug.rb', line 12 def initialize @active = false @destination = :print @save_html = false end |
Instance Attribute Details
#active ⇒ Object
Get debug active flag
4 5 6 |
# File 'lib/tiny_grabber/debug.rb', line 4 def active @active end |
#destination ⇒ Object
Get debug destination
6 7 8 |
# File 'lib/tiny_grabber/debug.rb', line 6 def destination @destination end |
#save_html ⇒ Object
Get debug flag to save response HTML to file
8 9 10 |
# File 'lib/tiny_grabber/debug.rb', line 8 def save_html @save_html end |
Instance Method Details
#save(message) ⇒ Object
Save log information
69 70 71 72 73 74 75 76 77 |
# File 'lib/tiny_grabber/debug.rb', line 69 def save = "TG | #{Time.now.strftime('%Y%m%d-%H%M%S')} | #{}" case @destination when :file save_to_file when :print p end end |
#save_to_file(message) ⇒ Object
Save log information to file
84 85 86 87 88 89 |
# File 'lib/tiny_grabber/debug.rb', line 84 def save_to_file debug_path = "#{Dir.pwd}/log" Dir.mkdir(debug_path, 0775) unless File.exists? debug_path filename = "#{Time.now.strftime('%Y%m%d')}.log" File.open("#{debug_path}/#{filename}", 'a+') { |f| f << "#{}\r\n" } end |