class Gemstash::Storage

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

Constants

VERSION

Public Class Methods

for(name) click to toggle source

Fetch a base entry in the storage engine.

@param name [String] the name of the entry to load @return [Gemstash::Storage] a new storage instance for the name

# File lib/gemstash/storage.rb, line 53
def self.for(name)
  new(gemstash_env.base_file(name))
end
metadata() click to toggle source

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

@return [Hash] the metadata about Gemstash and the storage engine

# File lib/gemstash/storage.rb, line 61
def self.metadata
  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
new(folder, root: true) click to toggle source

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

# 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

Public Instance Methods

for(child) click to toggle source

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

@param child [String] the name of the nested entry to load @return [Gemstash::Storage] a new storage instance for the child

# File lib/gemstash/storage.rb, line 45
def for(child)
  Storage.new(File.join(@folder, child), root: false)
end
resource(id) click to toggle source

Fetch the resource with the given id within this storage.

@param id [String] the id of the resource to fetch @return [Gemstash::Resource] a new resource instance from the id

# File lib/gemstash/storage.rb, line 37
def resource(id)
  Resource.new(@folder, id)
end

Private Instance Methods

check_storage_version() click to toggle source
# File lib/gemstash/storage.rb, line 76
def check_storage_version
  version = Gemstash::Storage.metadata[:storage_version]
  return if version <= Gemstash::Storage::VERSION

  raise Gemstash::Storage::VersionTooNew.new(@folder, version)
end
path_valid?(path) click to toggle source
# File lib/gemstash/storage.rb, line 83
def path_valid?(path)
  return false if path.nil?
  return false unless File.writable?(path)

  true
end