Class: Middleman::HashiCorp::Releases
- Inherits:
-
Object
- Object
- Middleman::HashiCorp::Releases
- Defined in:
- lib/middleman-hashicorp/releases.rb
Defined Under Namespace
Classes: Build
Constant Summary collapse
- RELEASES_URL =
"https://releases.hashicorp.com".freeze
Class Method Summary collapse
- .fetch(product, version) ⇒ Object
-
.fetch_latest_version(product) ⇒ Object
Gets only the most recently released version data for a given product.
Class Method Details
.fetch(product, version) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/middleman-hashicorp/releases.rb', line 8 def self.fetch(product, version) url = "#{RELEASES_URL}/#{product}/#{version}/index.json" r = JSON.parse(open(url).read, create_additions: false, symbolize_names: true, ) # Convert the builds into the following format: # # { # "os" => { # "arch" => "https://download.url" # } # } # {}.tap do |h| r[:builds].each do |b| build = Build.new(*b.values_at(*Build.members)) h[build.os] ||= {} h[build.os][build.arch] = build.url end end end |
.fetch_latest_version(product) ⇒ Object
Gets only the most recently released version data for a given product
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/middleman-hashicorp/releases.rb', line 36 def self.fetch_latest_version(product) url = "#{RELEASES_URL}/#{product}/index.json" res = JSON.parse(open(url).read, create_additions: false, symbolize_names: true, ) versions = res[:versions] # Releases are formatted as an object rather than an array in the JSON # structure, so we need to convert to an array then sort by version to # get the latest. We then return all info for that version. versions[versions.keys.sort_by(&Gem::Version.method(:new)).last] end |