Class: ErrorStalker::Store::Mongoid::ExceptionReport
- Inherits:
-
Object
- Object
- ErrorStalker::Store::Mongoid::ExceptionReport
- 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
-
.create_from_exception_report(exception_report) ⇒ Object
Create a new mongoid exception report from
exception_report.
Instance Method Summary collapse
-
#to_exception_report ⇒ Object
Generates an ErrorStalker::ExceptionReport from this model, converting the
datafield from a list of key-value pairs to a full-fledged hash.
Class Method Details
.create_from_exception_report(exception_report) ⇒ Object
Create a new mongoid exception report from exception_report.
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 |
# File 'lib/error_stalker/store/mongoid.rb', line 317 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_report ⇒ Object
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.
301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
# File 'lib/error_stalker/store/mongoid.rb', line 301 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 |