Skip to content
Browse files

Move backtrace cleaning to a module.

By moving the backtrace cleaning into a module and including it into the
notifier base we can include modules to add additional cleaning in
extension libraries.
  • Loading branch information...
1 parent 63aeb76 commit 2f3d65e7b4b8fe0b646623213a34164839b397f8 @Manfred Manfred committed Sep 3, 2012
Showing with 20 additions and 16 deletions.
  1. +20 −16 lib/peck/notifiers/base.rb
View
36 lib/peck/notifiers/base.rb
@@ -1,11 +1,26 @@
class Peck
class Notifiers
class Base
- # When a file starts with this path, it's in the Peck library
- PECK_PATH = File.expand_path('../../../../', __FILE__)
+ module BacktraceCleaning
+ # When a file starts with this path, it's in the Peck library
+ PECK_PATH = File.expand_path('../../../../', __FILE__)
- # Matches: `block (2 levels) in <top (required)>'
- ANONYMOUS_BLOCK_RE = /`block/
+ # Matches: `block (2 levels) in <top (required)>'
+ ANONYMOUS_BLOCK_RE = /`block/
+
+ def clean_backtrace(backtrace)
+ stripped = []
+ backtrace.each do |line|
+ if line.start_with?(PECK_PATH) || line.start_with?("<")
+ elsif line =~ ANONYMOUS_BLOCK_RE
+ stripped << line.split(':')[0,2].join(':')
+ else
+ stripped << line
+ end
+ end
+ stripped.empty? ? backtrace : stripped
+ end
+ end
def self.use
@instance ||= begin
@@ -22,18 +37,7 @@ def pluralize(count, stem)
count == 1 ? stem : "#{stem}s"
end
- def clean_backtrace(backtrace)
- stripped = []
- backtrace.each do |line|
- if line.start_with?(PECK_PATH) || line.start_with?("<")
- elsif line =~ ANONYMOUS_BLOCK_RE
- stripped << line.split(':')[0,2].join(':')
- else
- stripped << line
- end
- end
- stripped.empty? ? backtrace : stripped
- end
+ include BacktraceCleaning
end
end
end

0 comments on commit 2f3d65e

Please sign in to comment.
Something went wrong with that request. Please try again.