Sha256: b65612d36d0e0ef2480db0a356861cccb5581d04024e6ab537cabe17f6f44698

Contents?: true

Size: 935 Bytes

Versions: 17

Compression:

Stored size: 935 Bytes

Contents

module Footnotes
  module EachWithRescue
    def self.included(base)
      base.send :include, InstanceMethods
    end

    module InstanceMethods
      # Process notes, discarding only the note if any problem occurs
      #
      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

      # Logs the error using specified title and format
      #
      def log_error(title, exception)
        Rails.logger.error "#{title}: #{exception}\n#{exception.backtrace.join("\n")}"
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
rails-footnotes-7.1.0 lib/rails-footnotes/each_with_rescue.rb
rails-footnotes-7.0.1 lib/rails-footnotes/each_with_rescue.rb
rails-footnotes-7.0.0 lib/rails-footnotes/each_with_rescue.rb
rails-footnotes-5.0.0 lib/rails-footnotes/each_with_rescue.rb
rails6-footnotes-5.0.2 lib/rails-footnotes/each_with_rescue.rb
rails6-footnotes-5.0.1 lib/rails-footnotes/each_with_rescue.rb
rails6-footnotes-5.0.0 lib/rails-footnotes/each_with_rescue.rb
rails-footnotes-4.1.8 lib/rails-footnotes/each_with_rescue.rb
rails-footnotes-4.1.7 lib/rails-footnotes/each_with_rescue.rb
rails-footnotes-4.1.6 lib/rails-footnotes/each_with_rescue.rb
rails-footnotes-4.1.5 lib/rails-footnotes/each_with_rescue.rb
rails-footnotes-4.1.4 lib/rails-footnotes/each_with_rescue.rb
rails-footnotes-4.1.3 lib/rails-footnotes/each_with_rescue.rb
rails-footnotes-4.1.2 lib/rails-footnotes/each_with_rescue.rb
rails-footnotes-4.1.1 lib/rails-footnotes/each_with_rescue.rb
rails-footnotes-4.1.0 lib/rails-footnotes/each_with_rescue.rb
rails-footnotes-4.0.2 lib/rails-footnotes/each_with_rescue.rb