Sha256: ddac0ab4ae20c6a0c62d869d2a529a4b4471d5aeef41b15a301956eb31dbe820

Contents?: true

Size: 1.21 KB

Versions: 20

Compression:

Stored size: 1.21 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

    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

20 entries across 20 versions & 1 rubygems

Version Path
sentry-raven-2.5.3 lib/raven/breadcrumbs.rb
sentry-raven-2.5.2 lib/raven/breadcrumbs.rb
sentry-raven-2.5.1 lib/raven/breadcrumbs.rb
sentry-raven-2.5.0 lib/raven/breadcrumbs.rb
sentry-raven-2.4.0 lib/raven/breadcrumbs.rb
sentry-raven-2.3.1 lib/raven/breadcrumbs.rb
sentry-raven-2.3.0 lib/raven/breadcrumbs.rb
sentry-raven-2.2.0 lib/raven/breadcrumbs.rb
sentry-raven-2.1.4 lib/raven/breadcrumbs.rb
sentry-raven-2.1.3 lib/raven/breadcrumbs.rb
sentry-raven-2.1.2 lib/raven/breadcrumbs.rb
sentry-raven-2.1.1 lib/raven/breadcrumbs.rb
sentry-raven-2.1.0 lib/raven/breadcrumbs.rb
sentry-raven-2.0.2 lib/raven/breadcrumbs.rb
sentry-raven-2.0.1 lib/raven/breadcrumbs.rb
sentry-raven-2.0.0 lib/raven/breadcrumbs.rb
sentry-raven-1.2.3 lib/raven/breadcrumbs.rb
sentry-raven-1.2.2 lib/raven/breadcrumbs.rb
sentry-raven-1.2.1 lib/raven/breadcrumbs.rb
sentry-raven-1.2.0 lib/raven/breadcrumbs.rb