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.



27
28
29
30
31
# File 'lib/gemstash/storage.rb', line 27

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:



53
54
55
# File 'lib/gemstash/storage.rb', line 53

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



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/gemstash/storage.rb', line 61

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

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

  YAML.safe_load_file(file, permitted_classes: [Symbol])
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:



45
46
47
# File 'lib/gemstash/storage.rb', line 45

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:



37
38
39
# File 'lib/gemstash/storage.rb', line 37

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