Class: Mnenv::BinaryRepository
- Inherits:
-
Object
- Object
- Mnenv::BinaryRepository
- Defined in:
- lib/mnenv/binary_repository.rb
Overview
Repository for Binary (packed-mn) GitHub releases Supports both cached YAML data (from versions repo) and live API fallback
Constant Summary collapse
- PACKED_MN_REPO =
'metanorma/packed-mn'
Instance Attribute Summary collapse
-
#data_dir ⇒ Object
readonly
Returns the value of attribute data_dir.
Instance Method Summary collapse
-
#all ⇒ Object
Get all available binary versions.
-
#available_for_platform?(version_number) ⇒ Boolean
Check if a version is available for the current platform.
-
#count ⇒ Object
Count of available versions.
-
#find(version_number) ⇒ Object
Find a specific version.
-
#initialize(data_dir: nil, update: false) ⇒ BinaryRepository
constructor
A new instance of BinaryRepository.
-
#latest ⇒ Object
Get the latest version.
Constructor Details
#initialize(data_dir: nil, update: false) ⇒ BinaryRepository
Returns a new instance of BinaryRepository.
15 16 17 18 19 20 |
# File 'lib/mnenv/binary_repository.rb', line 15 def initialize(data_dir: nil, update: false) @data_dir = data_dir || default_data_dir @update = update @versions_cache = {} load end |
Instance Attribute Details
#data_dir ⇒ Object (readonly)
Returns the value of attribute data_dir.
13 14 15 |
# File 'lib/mnenv/binary_repository.rb', line 13 def data_dir @data_dir end |
Instance Method Details
#all ⇒ Object
Get all available binary versions
23 24 25 26 27 |
# File 'lib/mnenv/binary_repository.rb', line 23 def all # If cache is empty and not loaded from YAML, fall back to live API @versions_cache = fetch_from_api if @versions_cache.empty? && !@loaded_from_yaml @versions_cache.values.sort.reverse end |
#available_for_platform?(version_number) ⇒ Boolean
Check if a version is available for the current platform
36 37 38 39 40 41 42 43 |
# File 'lib/mnenv/binary_repository.rb', line 36 def available_for_platform?(version_number) version = find(version_number) return false unless version platform = detect_platform binary_name = "metanorma-#{platform}" version.assets.any? { |a| a == binary_name || a.include?(platform) } end |
#count ⇒ Object
Count of available versions
51 52 53 |
# File 'lib/mnenv/binary_repository.rb', line 51 def count @versions_cache.size end |
#find(version_number) ⇒ Object
Find a specific version
30 31 32 33 |
# File 'lib/mnenv/binary_repository.rb', line 30 def find(version_number) version_number = normalize_version(version_number) all.find { |v| v.version == version_number } end |
#latest ⇒ Object
Get the latest version
46 47 48 |
# File 'lib/mnenv/binary_repository.rb', line 46 def latest all.first end |