diff options
| author | Paul Buetow <paul@buetow.org> | 2026-05-25 21:27:28 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-05-25 21:27:28 +0300 |
| commit | 773ffb65bf36b7ec07549be1e291189e1f71c91e (patch) | |
| tree | 28736917cb8dd3c07976d7fae5fd27386a360331 | |
| parent | 578b0f747d8cf773c0e5ba9394bcf8436d6b0a01 (diff) | |
fix(client): use nil-safe fetch fallback in list_flavors/list_images
Replace || fallback with Hash#fetch block in list_flavors and list_images.
The old code incorrectly swapped falsy-but-present values (empty string,
false, 0) via ||. fetch only falls through when the key is absent,
preserving legitimate falsy values from the API.
| -rw-r--r-- | lib/hyperstack/client.rb | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/hyperstack/client.rb b/lib/hyperstack/client.rb index bb67318..7d81cd3 100644 --- a/lib/hyperstack/client.rb +++ b/lib/hyperstack/client.rb @@ -30,8 +30,8 @@ module HyperstackVM Array(response['data']).flat_map do |entry| Array(entry['flavors']).map do |flavor| flavor.merge( - 'region_name' => flavor['region_name'] || entry['region_name'], - 'gpu' => flavor['gpu'] || entry['gpu'] + 'region_name' => flavor.fetch('region_name') { entry['region_name'] }, + 'gpu' => flavor.fetch('gpu') { entry['gpu'] } ) end end @@ -42,8 +42,8 @@ module HyperstackVM Array(response['images']).flat_map do |entry| Array(entry['images']).map do |image| image.merge( - 'region_name' => image['region_name'] || entry['region_name'], - 'type' => image['type'] || entry['type'] + 'region_name' => image.fetch('region_name') { entry['region_name'] }, + 'type' => image.fetch('type') { entry['type'] } ) end end |
