Sha256: 39c3a454eb2f2731d6c5097e8ee063c2f7cf17fedbad9acbca4d8122dea60435

Contents?: true

Size: 896 Bytes

Versions: 5

Compression:

Stored size: 896 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
            # 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

5 entries across 5 versions & 1 rubygems

Version Path
rails-footnotes-4.0.1 lib/rails-footnotes/each_with_rescue.rb
rails-footnotes-4.0.0 lib/rails-footnotes/each_with_rescue.rb
rails-footnotes-3.7.9 lib/rails-footnotes/each_with_rescue.rb
rails-footnotes-3.7.8 lib/rails-footnotes/each_with_rescue.rb
rails-footnotes-3.7.7 lib/rails-footnotes/each_with_rescue.rb