File: set_metric.rb

package info (click to toggle)
ruby-sentry-ruby 5.18.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 564 kB
  • sloc: ruby: 4,701; makefile: 8; sh: 4
file content (28 lines) | stat: -rw-r--r-- 432 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# frozen_string_literal: true

require 'set'
require 'zlib'

module Sentry
  module Metrics
    class SetMetric < Metric
      attr_reader :value

      def initialize(value)
        @value = Set[value]
      end

      def add(value)
        @value << value
      end

      def serialize
        value.map { |x| x.is_a?(String) ? Zlib.crc32(x) : x.to_i }
      end

      def weight
        value.size
      end
    end
  end
end