Class: ErrorStalker::Store::Mongoid::ExceptionReport

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document
Defined in:
lib/error_stalker/store/mongoid.rb

Overview

The mongoid version of ErrorStalker::ExceptionReport. This class is used for mongo-specific querying and persistence of ExceptionReports, while base ExceptionReports are store-agnostic.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create_from_exception_report(exception_report) ⇒ Object

Create a new mongoid exception report from exception_report.



298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# File 'lib/error_stalker/store/mongoid.rb', line 298

def self.create_from_exception_report(exception_report)
  object = new do |o|
    [:application, :machine, :timestamp, :type, :exception, :digest].each do |field|
      o.send("#{field}=", exception_report.send(field))
    end

    # Store data as a list of key-value pairs, so the index on 'data' catches them all
    if exception_report.data && exception_report.data.kind_of?(Hash)
      o.data = [].tap do |array|
        exception_report.data.map {|key, value| array << {key => value}}
      end
    end
    
    if exception_report.backtrace
      o.backtrace = exception_report.backtrace
    end
  end
  object.save
  object
end

Instance Method Details

#to_exception_reportObject

Generates an ErrorStalker::ExceptionReport from this model, converting the data field from a list of key-value pairs to a full-fledged hash. Internally, we store it as a list of key->value to support fast multiattribute indexing, one of the cooler mongo features.



282
283
284
285
286
287
288
289
290
291
292
293
294
295
# File 'lib/error_stalker/store/mongoid.rb', line 282

def to_exception_report
  params = {}
  [:id, :application, :machine, :timestamp, :type, :exception, :digest, :backtrace].each do |field|
    params[field] = send(field)
  end
  
  if data
    params[:data] = {}.tap do |h|
      data.map { |hash| h[hash.keys.first] = hash[hash.keys.first] }
    end
  end
  
  ErrorStalker::ExceptionReport.new(params)
end