Class: Railsmdb::CryptShared::Catalog Private

Inherits:
Object
  • Object
show all
Defined in:
lib/railsmdb/crypt_shared/catalog.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A utility method for querying a catalog listing.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(listing) ⇒ Catalog

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create a new Catalog instance from the giving listing.

Parameters:

  • listing (Hash)

    the data to query



27
28
29
# File 'lib/railsmdb/crypt_shared/catalog.rb', line 27

def initialize(listing)
  @listing = listing
end

Instance Attribute Details

#listingHash (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the current listing.

Returns:

  • (Hash)

    the current listing



22
23
24
# File 'lib/railsmdb/crypt_shared/catalog.rb', line 22

def listing
  @listing
end

Class Method Details

.currentCatalog

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return a Catalog instance representing the current listing.

Returns:

  • (Catalog)

    the current listing.



16
17
18
# File 'lib/railsmdb/crypt_shared/catalog.rb', line 16

def current
  new(Listing.fetch)
end

Instance Method Details

#download_criteriaHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the download criteria (arch/target/edition) for the current host.

Returns:

  • (Hash)

    the download criteria



80
81
82
83
84
85
86
# File 'lib/railsmdb/crypt_shared/catalog.rb', line 80

def download_criteria
  {
    arch: platform_arch,
    target: platform_target,
    edition: 'enterprise'
  }
end

#downloads(criteria = {}) {|Hash| ... } ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Queries the listing data using the given criteria, yielding the corresponding download data.

Examples:

Finding all production releases for M1 macs

catalog.downloads(
  production_release: true,
  downloads: { arch: 'arm64', target: 'macos' }
) do |download|
  puts download['crypt_shared']['url']
end

Parameters:

  • criteria (Hash) (defaults to: {})

    the criteria hash

Yields:

  • (Hash)

    each download record matching the criteria



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/railsmdb/crypt_shared/catalog.rb', line 45

def downloads(criteria = {})
  download_criteria = criteria.delete(:downloads) || {}

  listing['versions'].each do |version|
    next unless hash_matches?(version, criteria)

    version['downloads'].each do |download|
      next unless hash_matches?(download, download_criteria)

      yield download
    end
  end

  self
end

#optimal_download_url_for_this_host(which = 'crypt_shared') ⇒ Array<String, String>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Queries the listing for all downloads that match the platform criteria for the current host.

Parameters:

  • which (String) (defaults to: 'crypt_shared')

    the download entry to return

Returns:

  • (Array<String, String>)

    a tuple of (url, sha256) for the requested download.



68
69
70
71
72
73
74
# File 'lib/railsmdb/crypt_shared/catalog.rb', line 68

def optimal_download_url_for_this_host(which = 'crypt_shared')
  downloads(production_release: true, downloads: download_criteria) do |dl|
    return [ dl[which]['url'], dl[which]['sha256'] ]
  end

  nil
end