Class: Gem::Guardian::ArtifactStore

Inherits:
Object
  • Object
show all
Defined in:
lib/gem/guardian/artifact_store.rb

Overview

Stores downloaded gem artifacts in a local cache directory.

Instance Method Summary collapse

Constructor Details

#initialize(client:, cache_dir: File.join(Dir.tmpdir, "gem-guardian")) ⇒ ArtifactStore

Returns a new instance of ArtifactStore.

Parameters:

  • client (RubygemsClient)

    downloader used when the artifact is not cached

  • cache_dir (String) (defaults to: File.join(Dir.tmpdir, "gem-guardian"))

    directory where downloaded artifacts are stored



12
13
14
15
# File 'lib/gem/guardian/artifact_store.rb', line 12

def initialize(client:, cache_dir: File.join(Dir.tmpdir, "gem-guardian"))
  @client = client
  @cache_dir = cache_dir
end

Instance Method Details

#path_for(dependency) ⇒ Object

Returns the local path for +dependency+, downloading it if needed.



18
19
20
21
22
23
24
# File 'lib/gem/guardian/artifact_store.rb', line 18

def path_for(dependency)
  FileUtils.mkdir_p(@cache_dir)
  path = File.join(@cache_dir, dependency.gem_filename)
  return path if File.file?(path)

  @client.download_gem(dependency, path)
end