Class: Fiveruns::Dash::ExceptionRecorder
- Defined in:
- lib/fiveruns/dash/exception_recorder.rb
Constant Summary collapse
- RULES =
[]
Class Method Summary collapse
- .add_ignore_rule(&rule) ⇒ Object
- .esc(path_prefixes) ⇒ Object
- .host ⇒ Object
- .path_prefixes(syspaths, suffix = '') ⇒ Object
- .regexp_for_path(path) ⇒ Object
- .replacements ⇒ Object
- .system_gempaths ⇒ Object
- .system_paths ⇒ Object
Instance Method Summary collapse
- #add_annotation(&annotation) ⇒ Object
- #data ⇒ Object
- #exception_annotations ⇒ Object
- #ignore_exception?(exception) ⇒ Boolean
-
#initialize(session) ⇒ ExceptionRecorder
constructor
A new instance of ExceptionRecorder.
- #record(exception, sample = nil) ⇒ Object
- #reset ⇒ Object
Constructor Details
#initialize(session) ⇒ ExceptionRecorder
Returns a new instance of ExceptionRecorder.
57 58 59 |
# File 'lib/fiveruns/dash/exception_recorder.rb', line 57 def initialize(session) @session = session end |
Class Method Details
.add_ignore_rule(&rule) ⇒ Object
51 52 53 |
# File 'lib/fiveruns/dash/exception_recorder.rb', line 51 def add_ignore_rule(&rule) RULES << rule end |
.esc(path_prefixes) ⇒ Object
47 48 49 |
# File 'lib/fiveruns/dash/exception_recorder.rb', line 47 def esc(path_prefixes) path_prefixes.collect{|path|Regexp.escape(path)}.join('|') end |
.host ⇒ Object
12 13 14 |
# File 'lib/fiveruns/dash/exception_recorder.rb', line 12 def host ::Fiveruns::Dash.host end |
.path_prefixes(syspaths, suffix = '') ⇒ Object
43 44 45 |
# File 'lib/fiveruns/dash/exception_recorder.rb', line 43 def path_prefixes(syspaths, suffix='') syspaths.strip.split(":").collect { |path| Pathname.new(path+suffix).cleanpath.to_s } end |
.regexp_for_path(path) ⇒ Object
39 40 41 |
# File 'lib/fiveruns/dash/exception_recorder.rb', line 39 def regexp_for_path(path) /^(#{Regexp.escape(Pathname.new(path).cleanpath.to_s)})/ end |
.replacements ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/fiveruns/dash/exception_recorder.rb', line 16 def replacements @replacements ||= begin paths = { :system => /^(#{esc(path_prefixes(system_paths))})/, :gems => /^(#{esc(path_prefixes(system_gempaths, '/gems'))})/ } %w(RAILS_ROOT MERB_ROOT).each do |root| const = nil const = Object.const_get(root) if Object.const_defined?(root) paths.merge({ :app => regexp_for_path(const) }) if const end paths end end |
.system_gempaths ⇒ Object
31 32 33 |
# File 'lib/fiveruns/dash/exception_recorder.rb', line 31 def system_gempaths host.result :gem, 'environment gempath', :bat end |
.system_paths ⇒ Object
35 36 37 |
# File 'lib/fiveruns/dash/exception_recorder.rb', line 35 def system_paths host.result :ruby, %(-e 'puts $:.reject { |p| p == "." }.join(":")'), :exe end |
Instance Method Details
#add_annotation(&annotation) ⇒ Object
101 102 103 |
# File 'lib/fiveruns/dash/exception_recorder.rb', line 101 def add_annotation(&annotation) exception_annotations << annotation end |
#data ⇒ Object
91 92 93 94 95 |
# File 'lib/fiveruns/dash/exception_recorder.rb', line 91 def data duped = exceptions.dup reset duped end |
#exception_annotations ⇒ Object
61 62 63 |
# File 'lib/fiveruns/dash/exception_recorder.rb', line 61 def exception_annotations @exception_annotaters ||= [] end |
#ignore_exception?(exception) ⇒ Boolean
65 66 67 68 69 |
# File 'lib/fiveruns/dash/exception_recorder.rb', line 65 def ignore_exception?(exception) RULES.any? do |rule| rule.call(exception) end end |
#record(exception, sample = nil) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/fiveruns/dash/exception_recorder.rb', line 71 def record(exception, sample=nil) return if ignore_exception? exception run_annotations(sample) data = extract_data_from_exception(exception) # Allow the sample data to override the exception's display name. data[:name] = sample.delete(:name) if sample and sample[:name] if (matching = existing_exception_for(data)) matching[:total] += 1 matching else data[:total] = 1 data[:sample] = flatten_sample sample exceptions << data data end end |
#reset ⇒ Object
97 98 99 |
# File 'lib/fiveruns/dash/exception_recorder.rb', line 97 def reset exceptions.clear end |