class Gemstash::Storage
The entry point into the storage engine for storing cached gems, specs, and private gems.
Constants
- VERSION
Public Class Methods
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
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
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
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
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
# 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
# File lib/gemstash/storage.rb, line 83 def path_valid?(path) return false if path.nil? return false unless File.writable?(path) true end