Class: FhirPackagesManager::Manager
- Inherits:
-
Object
- Object
- FhirPackagesManager::Manager
- Defined in:
- lib/fhir_packages_manager/manager.rb,
sig/fhir_packages_manager/manager.rbs
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.
- #download_result(package, found) ⇒ FetchResult
-
#fetch(package) ⇒ FetchResult
Fetches a single package.
-
#fetch_all(packages) ⇒ Array<FetchResult>
One result per package, in the same order.
- #fetch_package(package) ⇒ FetchResult
-
#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.
- #ignored?(package) ⇒ Boolean
-
#initialize(registries:, destination:, ignore_list: nil) ⇒ Manager
constructor
A new instance of Manager.
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 |
#download_result(package, found) ⇒ FetchResult
80 81 82 83 84 85 86 87 |
# File 'lib/fhir_packages_manager/manager.rb', line 80 def download_result(package, found) registry, resolved_version = found name = package.name target = File.join(destination, "#{name}-#{resolved_version}.tgz") registry.download(name, resolved_version, target) FetchResult.new(package: Package.new(name, resolved_version), status: :downloaded, registry: registry.base_url, path: target) 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 |
#fetch_package(package) ⇒ FetchResult
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/fhir_packages_manager/manager.rb', line 65 def fetch_package(package) return FetchResult.new(package: package, status: :ignored) if ignored?(package) found = find_registry(package.name, package.version) return FetchResult.new(package: package, status: :not_found) unless found download_result(package, found) rescue HttpError => e FetchResult.new(package: package, status: :error, error: e.) 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 |
#ignored?(package) ⇒ Boolean
76 77 78 |
# File 'lib/fhir_packages_manager/manager.rb', line 76 def ignored?(package) !!ignore_list&.ignored?(package.name, package.version) end |