Class: GoogleScribe
- Inherits:
-
Object
- Object
- GoogleScribe
- Defined in:
- lib/google_scribe.rb
Instance Attribute Summary collapse
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(url = nil) ⇒ GoogleScribe
constructor
A new instance of GoogleScribe.
-
#log_process(process_name, preserve_exceptions = true, &block) ⇒ Object
Will log the data returned by the block If the process fails, it will log the error message instead If preserve_exceptions is false, exceptions will fail silently otherwise, the exception will be logged normally.
- #send_data(data) ⇒ Object
Constructor Details
#initialize(url = nil) ⇒ GoogleScribe
Returns a new instance of GoogleScribe.
6 7 8 |
# File 'lib/google_scribe.rb', line 6 def initialize(url = nil) self.url = url end |
Instance Attribute Details
#url ⇒ Object
Returns the value of attribute url.
4 5 6 |
# File 'lib/google_scribe.rb', line 4 def url @url end |
Instance Method Details
#log_process(process_name, preserve_exceptions = true, &block) ⇒ Object
Will log the data returned by the block If the process fails, it will log the error message instead If preserve_exceptions is false, exceptions will fail silently otherwise, the exception will be logged normally
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/google_scribe.rb', line 18 def log_process(process_name, preserve_exceptions = true, &block) begin block_data = block.call process_data = { "Process" => process_name, "Success" => true } if block_data.is_a?(Hash) self.send_data(block_data.merge(process_data)) else self.send_data(process_data) end rescue Exception => e lines = e.backtrace.reject{|s| s.include?("/gems/") } = "#{ e.message } : #{ lines.first }" process_data = { "Process" => process_name, "Success" => false, "Error Message" => } self.send_data(process_data) raise e if preserve_exceptions end end |
#send_data(data) ⇒ Object
10 11 12 |
# File 'lib/google_scribe.rb', line 10 def send_data(data) GoogleSheetsClient.post(data, self.url) end |