Class: Gemstash::Storage

Inherits:
Object
  • Object
show all
Extended by:
Env::Helper
Defined in:
lib/gemstash/storage.rb

Overview

The entry point into the storage engine for storing cached gems, specs, and private gems.

Defined Under Namespace

Classes: VersionTooNew

Constant Summary collapse

VERSION =
1

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(folder, root: true) ⇒ Storage

This object should not be constructed directly, but instead via for and #for.



25
26
27
28
29
# File 'lib/gemstash/storage.rb', line 25

def initialize(folder, root: true)
  @folder = folder
  check_storage_version if root
  FileUtils.mkpath(@folder) unless Dir.exist?(@folder)
end

Class Method Details

.for(name) ⇒ Gemstash::Storage

Fetch a base entry in the storage engine.

Parameters:

  • name (String)

    the name of the entry to load

Returns:



51
52
53
# File 'lib/gemstash/storage.rb', line 51

def self.for(name)
  new(gemstash_env.base_file(name))
end

.metadataHash

Read the global metadata for Gemstash and the storage engine. If the metadata hasn’t been stored yet, it will be created.

Returns:

  • (Hash)

    the metadata about Gemstash and the storage engine



59
60
61
62
63
64
65
66
67
68
# File 'lib/gemstash/storage.rb', line 59

def self.
  file = gemstash_env.base_file("metadata.yml")

  unless File.exist?(file)
    File.write(file, { storage_version: Gemstash::Storage::VERSION,
                       gemstash_version: Gemstash::VERSION }.to_yaml)
  end

  YAML.load_file(file)
end

Instance Method Details

#for(child) ⇒ Gemstash::Storage

Fetch a nested entry from this instance in the storage engine.

Parameters:

  • child (String)

    the name of the nested entry to load

Returns:



43
44
45
# File 'lib/gemstash/storage.rb', line 43

def for(child)
  Storage.new(File.join(@folder, child), root: false)
end

#resource(id) ⇒ Gemstash::Resource

Fetch the resource with the given id within this storage.

Parameters:

  • id (String)

    the id of the resource to fetch

Returns:



35
36
37
# File 'lib/gemstash/storage.rb', line 35

def resource(id)
  Resource.new(@folder, id)
end