Class: FhirPackagesManager::Manager
- Inherits:
-
Object
- Object
- FhirPackagesManager::Manager
- Defined in:
- lib/fhir_packages_manager/manager.rb
Overview
Orchestrates checking availability across a set of registries, honoring an ignore list, and downloading tarballs into a destination folder.
Instance Attribute Summary collapse
-
#destination ⇒ String
readonly
The folder packages are downloaded into.
-
#ignore_list ⇒ IgnoreList?
readonly
Packages/versions skipped by #fetch.
-
#registries ⇒ Array<Registry>
readonly
Registries checked, in the order given to #initialize.
Instance Method Summary collapse
-
#available?(name, version = nil) ⇒ Boolean
True if any configured registry has this package/version.
-
#fetch(package) ⇒ FetchResult
Fetches a single package.
-
#fetch_all(packages) ⇒ Array<FetchResult>
One result per package, in the same order.
-
#find_registry(name, version = nil) ⇒ Array(Registry, String)?
The first registry that has this package/version, paired with the resolved version string; nil if none of them do.
-
#initialize(registries:, destination:, ignore_list: nil) ⇒ Manager
constructor
A new instance of Manager.
-
#list_versions(name) ⇒ Hash{String => Array<String>}
Lists every version of a package published across all configured registries, skipping registries that don't have it at all and filtering out any ignored versions.
-
#sync(name) ⇒ Array<FetchResult>
Downloads every non-ignored version of a package that isn't already present in #destination (as
name-version.tgz, the same convention #fetch downloads use).
Constructor Details
#initialize(registries:, destination:, ignore_list: nil) ⇒ Manager
Returns a new instance of Manager.
21 22 23 24 25 26 27 |
# File 'lib/fhir_packages_manager/manager.rb', line 21 def initialize(registries:, destination:, ignore_list: nil) raise ArgumentError, 'at least one registry is required' if registries.nil? || registries.empty? @registries = registries.map { |entry| entry.is_a?(Registry) ? entry : Registry.new(entry) } @destination = destination.to_s @ignore_list = ignore_list end |
Instance Attribute Details
#destination ⇒ String (readonly)
Returns the folder packages are downloaded into.
12 13 14 |
# File 'lib/fhir_packages_manager/manager.rb', line 12 def destination @destination end |
#ignore_list ⇒ IgnoreList? (readonly)
Returns packages/versions skipped by #fetch.
14 15 16 |
# File 'lib/fhir_packages_manager/manager.rb', line 14 def ignore_list @ignore_list end |
#registries ⇒ Array<Registry> (readonly)
Returns registries checked, in the order given to #initialize.
10 11 12 |
# File 'lib/fhir_packages_manager/manager.rb', line 10 def registries @registries end |
Instance Method Details
#available?(name, version = nil) ⇒ Boolean
Returns true if any configured registry has this package/version.
32 33 34 |
# File 'lib/fhir_packages_manager/manager.rb', line 32 def available?(name, version = nil) !find_registry(name, version).nil? end |
#fetch(package) ⇒ FetchResult
Fetches a single package. Skips it if it's on the ignore list, otherwise downloads its tarball into #destination.
53 54 55 |
# File 'lib/fhir_packages_manager/manager.rb', line 53 def fetch(package) fetch_package(Package.parse(package)) end |
#fetch_all(packages) ⇒ Array<FetchResult>
Returns one result per package, in the same order.
59 60 61 |
# File 'lib/fhir_packages_manager/manager.rb', line 59 def fetch_all(packages) packages.map { |package| fetch(package) } end |
#find_registry(name, version = nil) ⇒ Array(Registry, String)?
Returns the first registry that has this package/version, paired with the resolved version string; nil if none of them do.
40 41 42 43 44 45 46 |
# File 'lib/fhir_packages_manager/manager.rb', line 40 def find_registry(name, version = nil) registries.each do |registry| resolved = registry.version?(name, version) return [registry, resolved] if resolved end nil end |
#list_versions(name) ⇒ Hash{String => Array<String>}
Lists every version of a package published across all configured registries, skipping registries that don't have it at all and filtering out any ignored versions.
73 74 75 76 77 78 79 80 81 |
# File 'lib/fhir_packages_manager/manager.rb', line 73 def list_versions(name) result = {} # : Hash[String, Array[String]] return result if ignored?(Package.new(name, nil)) registries.each_with_object(result) do |registry, found| versions = available_versions(registry, name) found[registry.base_url] = versions unless versions.empty? end end |
#sync(name) ⇒ Array<FetchResult>
Downloads every non-ignored version of a package that isn't already present in
#destination (as name-version.tgz, the same convention #fetch downloads use).
A whole-package ignore skips it entirely, without querying any registry; an individual
ignored version instead surfaces as a normal :ignored FetchResult, same as #fetch.
90 91 92 93 94 95 |
# File 'lib/fhir_packages_manager/manager.rb', line 90 def sync(name) whole_package = Package.new(name, nil) return [FetchResult.new(package: whole_package, status: :ignored)] if ignored?(whole_package) candidate_versions(name).map { |version| sync_version(Package.new(name, version)) } end |