Sha256: 55dd19941f34c2dac398fc55844266298c7f61d1b1bfaff5f59e19e9c2f46c02

Contents?: true

Size: 1.23 KB

Versions: 23

Compression:

Stored size: 1.23 KB

Contents

module Raven
  class Breadcrumb
    attr_accessor :category, :data, :message, :level, :timestamp, :type

    def initialize
      @category = nil
      @data = {}
      @level = nil
      @message = nil
      @timestamp = Time.now.to_i
      @type = nil
    end

    def to_hash
      {
        :category => @category,
        :data => @data,
        :level => @level,
        :message => @message,
        :timestamp => @timestamp,
        :type => @type
      }
    end
  end
end

module Raven
  class BreadcrumbBuffer
    include Enumerable

    attr_accessor :buffer

    def self.current
      Thread.current[:sentry_breadcrumbs] ||= new
    end

    def self.clear!
      Thread.current[:sentry_breadcrumbs] = nil
    end

    def initialize(size = 100)
      @buffer = Array.new(size)
    end

    def record(crumb = nil)
      if block_given?
        crumb = Breadcrumb.new if crumb.nil?
        yield(crumb)
      end
      @buffer.slice!(0)
      @buffer << crumb
    end

    def members
      @buffer.compact
    end

    def peek
      members.last
    end

    def each(&block)
      members.each(&block)
    end

    def empty?
      !members.any?
    end

    def to_hash
      {
        :values => members.map(&:to_hash)
      }
    end
  end
end

Version data entries

23 entries across 23 versions & 3 rubygems

Version Path
sentry-raven-2.6.2 lib/raven/breadcrumbs.rb
sentry-raven-2.6.1 lib/raven/breadcrumbs.rb
sentry-raven-2.6.0 lib/raven/breadcrumbs.rb