Sha256: 7d57e323808af2067f3aaacefa387ef1f24177cbb4b0e29653fa58cd0c4a2a25

Contents?: true

Size: 1.57 KB

Versions: 2

Compression:

Stored size: 1.57 KB

Contents

require 'mongo'

module YogiBerra
  class Data
    def self.store!(exception, environment = nil)
      data = parse_exception(exception)
      if environment
        session = environment.delete(:session)
        data[:session] = parse_session(session) if session
        controller = environment.delete(:controller)
        data[:controller] = parse_controller(controller) if controller
        data.merge!(environment)
      end
      YogiBerra::Catcher.connection["caught_exceptions"].insert(data)
    end

    def self.parse_exception(notice)
      data_hash = {
        :error_class => "#{notice.exception.class}",
        :project => YogiBerra::Catcher.settings["project"],
        :error_message => notice.respond_to?(:error_message) ? notice.error_message : notice.message
      }
      data_hash[:backtraces] = notice.backtrace
      if notice.backtrace.respond_to?(:lines) && notice.backtrace.lines.any?
        data_hash[:backtraces] = notice.backtrace.lines.collect(&:to_s)
      end
      data_hash[:created_at] = Time.now.utc
      data_hash
    end

    def self.parse_session(session)
      session.inject({}) do |result, element|
        key = element.first
        value = element.last
        if value.respond_to?(:as_json)
          result[key] = value.as_json(:except => ["password"])
        else
          value.delete("password")
          result[key] = value
        end
        result
      end
    end

    def self.parse_controller(controller)
      if controller
        { :action => controller.action_name, :name => controller.controller_name }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
yogi_berra-0.1.3 lib/yogi_berra/data.rb
yogi_berra-0.1.1 lib/yogi_berra/data.rb