Class: Capsium::Registry
- Inherits:
-
Object
- Object
- Capsium::Registry
- Defined in:
- lib/capsium/registry.rb,
lib/capsium/registry/local.rb,
lib/capsium/registry/remote.rb,
sig/capsium/registry.rbs,
sig/capsium/registry/local.rbs,
sig/capsium/registry/remote.rbs
Overview
A static package registry (directory or https base URL with an index.json): Capsium::Registry::Local (read-write) and Capsium::Registry::Remote (read-only). See lib/capsium/registry.rb.
Defined Under Namespace
Classes: ChecksumMismatchError, Entry, FetchError, InvalidPackageError, InvalidRegistryError, Local, PackageNotFoundError, RegistryError, RegistryNotConfiguredError, Remote, UnsatisfiableConstraintError
Constant Summary collapse
- INDEX_FILE =
"index.json"- ENV_VAR =
"CAPSIUM_REGISTRY"
Class Method Summary collapse
-
.default ⇒ Registry?
The registry named by the CAPSIUM_REGISTRY environment variable, or nil when unset.
-
.fetch(ref) ⇒ Registry
The registry at the given reference: a Local directory or a Remote http(s) base URL.
Instance Method Summary collapse
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
-
#install(guid, constraint = "*", store:) ⇒ Object
Resolves, fetches, checksum-verifies and installs the newest satisfying .cap into the package store, returning the store path.
-
#location ⇒ String
Where this registry lives (directory path or base URL).
-
#push(_cap_path) ⇒ Entry
Only Local registries are writable.
-
#resolve(guid, constraint = "*") ⇒ Entry
The newest indexed version of the package GUID satisfying the semver constraint.
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
78 79 80 |
# File 'lib/capsium/registry.rb', line 78 def initialize @index = nil end |
Class Method Details
.default ⇒ Registry?
The registry named by the CAPSIUM_REGISTRY environment variable, or nil when unset.
72 73 74 75 |
# File 'lib/capsium/registry.rb', line 72 def default ref = ENV.fetch(ENV_VAR, nil) ref.nil? || ref.empty? ? nil : fetch(ref) end |
.fetch(ref) ⇒ Registry
The registry at the given reference: a Local directory or a Remote http(s) base URL. Raises RegistryNotConfiguredError when no reference is given.
61 62 63 64 65 66 67 68 |
# File 'lib/capsium/registry.rb', line 61 def fetch(ref) if ref.nil? || ref.to_s.empty? raise RegistryNotConfiguredError, "no registry configured (pass --registry or set #{ENV_VAR})" end ref.to_s.match?(%r{\Ahttps?://}) ? Remote.new(ref.to_s) : Local.new(ref.to_s) end |
Instance Method Details
#install(guid, constraint = "*", store:) ⇒ Object
Resolves, fetches, checksum-verifies and installs the newest satisfying .cap into the package store, returning the store path.
104 105 106 107 108 109 110 |
# File 'lib/capsium/registry.rb', line 104 def install(guid, constraint = "*", store:) entry = resolve(guid, constraint) with_entry_file(entry) do |path| verify_checksum!(entry, path) store_for(store).install(path, guid: entry.guid, file_name: entry.cap_file_name) end end |
#location ⇒ String
Where this registry lives (directory path or base URL).
84 |
# File 'lib/capsium/registry.rb', line 84 def location = raise(NotImplementedError) |
#push(_cap_path) ⇒ Entry
Only Local registries are writable.
113 114 115 |
# File 'lib/capsium/registry.rb', line 113 def push(_cap_path) raise RegistryError, "registry is read-only: #{location}" end |
#resolve(guid, constraint = "*") ⇒ Entry
The newest indexed version of the package GUID satisfying the semver constraint.
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/capsium/registry.rb', line 89 def resolve(guid, constraint = "*") listing = packages[guid] raise PackageNotFoundError, "no package #{guid} in registry #{location}" if listing.nil? versions = listing_versions(guid, listing) range = Package::VersionRange.parse(constraint) = versions.keys.select { |version| range.satisfied_by?(version) } raise_unsatisfiable(guid, constraint, versions) if .empty? entry_for(guid, listing, .max) end |