Sha256: 1bf0d6236d69593a7c166a43416ce24a6483f7e5f57317182e568b091db3afbd

Contents?: true

Size: 1.1 KB

Versions: 8

Compression:

Stored size: 1.1 KB

Contents

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

module Contrast
  module Agent
    module Inventory
      # Keeps a map of gem digest to files for reporting file usage
      class GemfileDigestCache
        extend Forwardable
        def_delegator :@gem_spec_digest_to_files,
                      :empty?

        def initialize
          @gem_spec_digest_to_files = {}
        end

        def generate_usage_data activity
          return unless activity

          @gem_spec_digest_to_files.each_pair do |digest, files|
            usage = Contrast::Api::Dtm::LibraryUsageUpdate.build(digest, files)
            activity.library_usages[usage.hash_code] = usage if activity
          end
          @gem_spec_digest_to_files.clear
        end

        def use_cache digest
          yield get(digest)
        end

        def get digest
          @gem_spec_digest_to_files[digest] = Set.new unless @gem_spec_digest_to_files.key?(digest)
          @gem_spec_digest_to_files[digest]
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
contrast-agent-4.4.1 lib/contrast/agent/inventory/gemfile_digest_cache.rb
contrast-agent-4.4.0 lib/contrast/agent/inventory/gemfile_digest_cache.rb
contrast-agent-4.3.2 lib/contrast/agent/inventory/gemfile_digest_cache.rb
contrast-agent-4.3.1 lib/contrast/agent/inventory/gemfile_digest_cache.rb
contrast-agent-4.3.0 lib/contrast/agent/inventory/gemfile_digest_cache.rb
contrast-agent-4.2.0 lib/contrast/agent/inventory/gemfile_digest_cache.rb
contrast-agent-4.1.0 lib/contrast/agent/inventory/gemfile_digest_cache.rb
contrast-agent-4.0.0 lib/contrast/agent/inventory/gemfile_digest_cache.rb