Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[^] Filter#each_with_rescue has been extracted to separate module
- Loading branch information
1 parent
9edbc36
commit c66776d
Showing
3 changed files
with
41 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
module Footnotes | ||
autoload :BeforeFilter, 'rails-footnotes/before_filter' | ||
autoload :AfterFilter, 'rails-footnotes/after_filter' | ||
autoload :Filter, 'rails-footnotes/filter' | ||
autoload :EachWithRescue, 'rails-footnotes/each_with_rescue' | ||
|
||
autoload :BeforeFilter, 'rails-footnotes/before_filter' | ||
autoload :AfterFilter, 'rails-footnotes/after_filter' | ||
autoload :Filter, 'rails-footnotes/filter' | ||
end |