Class: Capsium::Package::Store
- Inherits:
-
Object
- Object
- Capsium::Package::Store
- Defined in:
- lib/capsium/package/store.rb,
sig/capsium/package/store.rbs
Overview
A package store directory (ARCHITECTURE.md section 4a):
"
Defined Under Namespace
Classes: CatalogEntry
Constant Summary collapse
- INDEX_FILE =
"index.json"- CAP_GLOB =
"*.cap"
Instance Attribute Summary collapse
-
#dir ⇒ String
readonly
Returns the value of attribute dir.
Class Method Summary collapse
-
.default ⇒ Store?
The store configured via the CAPSIUM_STORE environment variable, or nil when unset.
Instance Method Summary collapse
-
#catalog ⇒ Array[CatalogEntry]
Every .cap in the store with its metadata identity (memoized).
-
#find(guid, range_string) ⇒ String
The newest .cap providing the dependency GUID whose version satisfies the range string.
-
#initialize(dir) ⇒ Store
constructor
A new instance of Store.
Constructor Details
#initialize(dir) ⇒ Store
Returns a new instance of Store.
29 30 31 32 33 34 35 |
# File 'lib/capsium/package/store.rb', line 29 def initialize(dir) unless File.directory?(dir) raise DependencyError, "Package store directory not found: #{dir}" end @dir = dir end |
Instance Attribute Details
#dir ⇒ String (readonly)
Returns the value of attribute dir.
20 21 22 |
# File 'lib/capsium/package/store.rb', line 20 def dir @dir end |
Class Method Details
.default ⇒ Store?
The store configured via the CAPSIUM_STORE environment variable, or nil when unset.
24 25 26 27 |
# File 'lib/capsium/package/store.rb', line 24 def self.default dir = ENV.fetch("CAPSIUM_STORE", nil) dir.nil? || dir.empty? ? nil : new(dir) end |
Instance Method Details
#catalog ⇒ Array[CatalogEntry]
Every .cap in the store with its metadata identity (memoized).
60 61 62 63 64 |
# File 'lib/capsium/package/store.rb', line 60 def catalog @catalog ||= Dir.glob(File.join(@dir, CAP_GLOB)).map do |path| catalog_entry(path) end end |
#find(guid, range_string) ⇒ String
The newest .cap providing the dependency GUID whose version satisfies the range string. Raises DependencyNotFoundError or UnsatisfiableDependencyError when it cannot.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/capsium/package/store.rb', line 39 def find(guid, range_string) range = VersionRange.parse(range_string) indexed = indexed_path(guid) return (indexed, guid, range_string, range) if indexed candidates = catalog.select { |entry| entry.guid == guid } if candidates.empty? raise DependencyNotFoundError, "no package for dependency #{guid} in store #{@dir}" end = candidates.select { |entry| range.satisfied_by?(entry.version) } return .max_by(&:version).path unless .empty? versions = candidates.map { |entry| entry.version.to_s }.sort.join(", ") raise UnsatisfiableDependencyError, "no version of #{guid} satisfies '#{range_string}' " \ "(store has: #{versions})" end |