Sha256: 307337642ccb6e18e5e273e47018daef8dca3366ef145dcdf758e9f88a359ad2

Contents?: true

Size: 1.83 KB

Versions: 4

Compression:

Stored size: 1.83 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 Agent
    module Reporting
      # This module will be used to store everything that would be sent
      # and depends on the response we receive
      module ReportingStorage
        class << self
          include Contrast::Components::Logger::InstanceMethods

          # So the collection will be used to store those events
          def collection
            @_collection ||= {}
          end

          # @param key[String] the key for the pair
          # @param value[Object] the value we need to store
          # @return [Object] the value we saved
          def []= key, value
            return unless key
            return unless value

            logger.debug('Saving new value', key: key)

            key = key.to_s.downcase.strip
            collection[key] = value

            value # rubocop:disable Lint/Void
          end

          # @param key[String] the key for the pair
          def [] key
            return unless key

            collection[key]
          end
          alias_method :get, :[]
          alias_method :set, :[]=

          def delete key
            return unless key

            logger.debug('Starting deleting value for', key: key)

            deleted_value = collection.delete(key)
            logger.debug('Key wasn\'t found') unless deleted_value

            deleted_value
          end

          # @param rule_id [String] the rule_id
          # @return [Hash, nil] return array with key and value of the pair
          def find_by_rule_id rule_id
            return unless rule_id

            collection.find { |_, v| v.rule_id == rule_id }
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
contrast-agent-5.3.0 lib/contrast/agent/reporting/reporting_utilities/reporting_storage.rb
contrast-agent-5.2.0 lib/contrast/agent/reporting/reporting_utilities/reporting_storage.rb
contrast-agent-5.1.0 lib/contrast/agent/reporting/reporting_utilities/reporting_storage.rb
contrast-agent-5.0.0 lib/contrast/agent/reporting/reporting_utilities/reporting_storage.rb