Class: FhirPackagesManager::Registry
- Inherits:
-
Object
- Object
- FhirPackagesManager::Registry
- Defined in:
- lib/fhir_packages_manager/registry.rb
Overview
Client for a single FHIR package registry (e.g. https://packages.fhir.org
or https://packages.simplifier.net). Both implement the same npm-style
registry API: GET /<package> returns metadata with a "versions" map and
"dist-tags", and GET /<package>/<version> streams the .tgz tarball.
Constant Summary collapse
- MAX_REDIRECTS =
Returns maximum HTTP redirects followed before raising HttpError.
5
Instance Attribute Summary collapse
-
#base_url ⇒ String
readonly
The registry's base URL, with any trailing slash stripped.
Instance Method Summary collapse
-
#download(name, version, destination_path) ⇒ String
Downloads the package tarball to destination_path, creating parent directories as needed.
-
#initialize(base_url) ⇒ Registry
constructor
A new instance of Registry.
-
#metadata(name) ⇒ Hash
Fetches (and caches) the full registry metadata document for a package name.
-
#tarball_url(name, version) ⇒ String
The tarball's download URL.
-
#version?(name, version = nil) ⇒ String?
The resolved version string if it exists on this registry, or nil if the package or version doesn't exist (never raises).
-
#versions(name) ⇒ Array<String>
Every version published for this package on this registry.
Constructor Details
#initialize(base_url) ⇒ Registry
Returns a new instance of Registry.
21 22 23 24 |
# File 'lib/fhir_packages_manager/registry.rb', line 21 def initialize(base_url) @base_url = base_url.to_s.chomp('/') @metadata_cache = {} # : Hash[String, Hash[untyped, untyped]] end |
Instance Attribute Details
#base_url ⇒ String (readonly)
Returns the registry's base URL, with any trailing slash stripped.
18 19 20 |
# File 'lib/fhir_packages_manager/registry.rb', line 18 def base_url @base_url end |
Instance Method Details
#download(name, version, destination_path) ⇒ String
Downloads the package tarball to destination_path, creating parent directories as needed.
80 81 82 83 84 |
# File 'lib/fhir_packages_manager/registry.rb', line 80 def download(name, version, destination_path) FileUtils.mkdir_p(File.dirname(destination_path)) download_file(tarball_url(name, version), destination_path) destination_path end |
#metadata(name) ⇒ Hash
Fetches (and caches) the full registry metadata document for a package name.
32 33 34 35 36 37 38 |
# File 'lib/fhir_packages_manager/registry.rb', line 32 def (name) @metadata_cache[name] ||= JSON.parse(get("#{base_url}/#{name}")) rescue HttpError => e raise PackageNotFoundError, "#{name} not found on #{base_url}" if e.status == 404 raise end |
#tarball_url(name, version) ⇒ String
Returns the tarball's download URL.
64 65 66 67 68 69 70 |
# File 'lib/fhir_packages_manager/registry.rb', line 64 def tarball_url(name, version) = (name) entry = .dig('versions', version) raise PackageNotFoundError, "#{name}@#{version} not found on #{base_url}" unless entry entry.dig('dist', 'tarball') || "#{base_url}/#{name}/#{version}" end |
#version?(name, version = nil) ⇒ String?
Returns the resolved version string if it exists on this registry, or nil if the package or version doesn't exist (never raises).
44 45 46 47 48 49 50 |
# File 'lib/fhir_packages_manager/registry.rb', line 44 def version?(name, version = nil) = (name) resolved = resolve_version(, version) resolved && ['versions']&.key?(resolved) ? resolved : nil rescue PackageNotFoundError nil end |
#versions(name) ⇒ Array<String>
Returns every version published for this package on this registry.
56 57 58 |
# File 'lib/fhir_packages_manager/registry.rb', line 56 def versions(name) (name)['versions']&.keys || [] end |