Class: FhirPackagesManager::IgnoreList

Inherits:
Object
  • Object
show all
Defined in:
lib/fhir_packages_manager/ignore_list.rb,
sig/fhir_packages_manager/ignore_list.rbs

Overview

A list of packages (optionally pinned to a version) to skip when fetching.

Loaded from a YAML or JSON file containing a flat array, e.g.:

- hl7.fhir.r4.core           # ignore every version of this package
- name: hl7.fhir.us.core
version: 3.1.0             # ignore only this one version

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entries = []) ⇒ IgnoreList

Returns a new instance of IgnoreList.

Parameters:

  • entries (Array<String, Hash>) (defaults to: [])

    bare package names (ignore every version) and/or {"name" => ..., "version" => ...} hashes (ignore only that version)

Raises:

  • (ArgumentError)

    if an entry is neither a String nor a Hash



32
33
34
# File 'lib/fhir_packages_manager/ignore_list.rb', line 32

def initialize(entries = [])
  @entries = entries.map { |entry| normalize(entry) }
end

Class Method Details

.load(path) ⇒ IgnoreList

Loads an ignore list from a YAML or JSON file (JSON iff the extension is .json).

Parameters:

  • path (String)

    path to a YAML or JSON file containing a flat array of entries

Returns:



19
20
21
22
23
24
25
26
27
# File 'lib/fhir_packages_manager/ignore_list.rb', line 19

def self.load(path)
  data = case File.extname(path).downcase
         when '.json'
           JSON.parse(File.read(path))
         else
           YAML.load_file(path)
         end
  new(data || [])
end

Instance Method Details

#ignored?(name, version = nil) ⇒ Boolean

Returns true if this name/version is on the ignore list.

Parameters:

  • name (String)

    the package name

  • version (String, nil) (defaults to: nil)

    the version being requested, if any

Returns:

  • (Boolean)

    true if this name/version is on the ignore list



39
40
41
# File 'lib/fhir_packages_manager/ignore_list.rb', line 39

def ignored?(name, version = nil)
  @entries.any? { |entry| matches?(entry, name, version) }
end

#matches?(entry, name, version) ⇒ Boolean

Parameters:

  • entry (Hash[Symbol, String?])
  • name (String)
  • version (String, nil)

Returns:

  • (Boolean)


45
46
47
48
49
50
# File 'lib/fhir_packages_manager/ignore_list.rb', line 45

def matches?(entry, name, version)
  return false unless entry[:name] == name

  ignored_version = entry[:version]
  ignored_version.nil? || ignored_version == version
end

#normalize(entry) ⇒ Hash[Symbol, String?]

Parameters:

  • entry (String, Hash[untyped, untyped])

Returns:

  • (Hash[Symbol, String?])


52
53
54
55
56
57
58
59
60
61
# File 'lib/fhir_packages_manager/ignore_list.rb', line 52

def normalize(entry)
  case entry
  when String
    { name: entry, version: nil }
  when Hash
    normalize_hash(entry)
  else
    raise ArgumentError, "Invalid ignore list entry: #{entry.inspect}"
  end
end

#normalize_hash(entry) ⇒ Hash[Symbol, String?]

Parameters:

  • entry (Hash[untyped, untyped])

Returns:

  • (Hash[Symbol, String?])


63
64
65
66
# File 'lib/fhir_packages_manager/ignore_list.rb', line 63

def normalize_hash(entry)
  version = entry['version'] || entry[:version]
  { name: entry['name'] || entry[:name], version: version&.to_s }
end