Sha256: 14af45c1cc50853f62025810e2ccd21b096d8b53ca6c81ce3d9956e6c3cf132e

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

# Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
# frozen_string_literal: true

require 'contrast/components/logger'

module Contrast
  module Utils
    # This is the TelemetryHash, which will take data type, so we can push freely, without worrying about
    # validating the event before that
    class TelemetryHash < Hash
      include Contrast::Components::Logger::InstanceMethods

      attr_reader :data_type

      def initialize data_type, *_several_variants
        super()
        @data_type = data_type
      end

      def []= key, value
        return unless valid_value? value

        super(key, value)
      end

      def increment key
        self[key].exceptions[0].increment_occurrences
        :incremented!
      end

      def valid_value? value
        unless value.cs__is_a?(data_type)
          logger.debug('The following key will be omitted', value: value)
          return false
        end

        true
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
contrast-agent-6.1.0 lib/contrast/utils/telemetry_hash.rb