Module: Footnotes::EachWithRescue::InstanceMethods
- Defined in:
- lib/rails-footnotes/each_with_rescue.rb
Instance Method Summary collapse
-
#each_with_rescue(collection) ⇒ Object
Process notes, discarding only the note if any problem occurs.
-
#log_error(title, exception) ⇒ Object
Logs the error using specified title and format.
Instance Method Details
#each_with_rescue(collection) ⇒ Object
Process notes, discarding only the note if any problem occurs
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rails-footnotes/each_with_rescue.rb', line 10 def each_with_rescue(collection) delete_me = [] collection.each do |item| begin yield item rescue Exception => e raise e if Rails.env.test? # Discard item if it has a problem log_error("Footnotes #{item.to_s.camelize} Exception", e) delete_me << item next end end delete_me.each { |item| collection.delete(item) } return collection end |
#log_error(title, exception) ⇒ Object
Logs the error using specified title and format
31 32 33 |
# File 'lib/rails-footnotes/each_with_rescue.rb', line 31 def log_error(title, exception) Rails.logger.error "#{title}: #{exception}\n#{exception.backtrace.join("\n")}" end |