debian_codename 0.2.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/debian_codename.rb +40 -5
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78b5e4e8d7b141d02e8986d7c7f6ced3a07a1c9dd8bd8f6fe75dcb96e892f74d
4
- data.tar.gz: c7cc6214ce8b243c32dfb2a1251b0a2497a03b754743858dee2271847cd69e37
3
+ metadata.gz: c363a439873bce2913c1a7612cd3163044671a5b511f05000d899a54049babc4
4
+ data.tar.gz: 9cff5cd8b29cc2065001ee8bbfbd1fc7aff2d751c75470cc67f6f8792912051e
5
5
  SHA512:
6
- metadata.gz: d3dcb7ebd8093be1954581c4c1c261cc2f069f2f919faa92d401e26935f74125c24aa33d292c0eb9459bd1e30fe4d2dddfee48714c2fcad81324b44afd523152
7
- data.tar.gz: cbb9184b43e25989750f542692e027037ab087250b269e58d9825e6d6a98627ca9a133bef8ebc078ec91b9b4a9b70041cda66a68397f170b1c8116dfd9531269
6
+ metadata.gz: 6c9bfc361fddd81f609896772407e780a6374bd0587c9f6bfdda4002a0e19f0523983514eac16b176fd3039772681482ceff4d115e0ac4f21bb320dd863e7a44
7
+ data.tar.gz: 13d9c211b2bc1e0d7bae669f3f4de4801e58a5b8bdbff328f0d2578b881e5e99cf9e4417c4f3cf78406fbe1cb1c53da29f9613271877e51a1029ac1e949bc8c4
@@ -7,6 +7,7 @@ module DebianCodename
7
7
 
8
8
  # https://wiki.debian.org/DebianReleases#Production_Releases
9
9
  DEBIAN_CODENAMES = {
10
+ '@distribution' => 'debian',
10
11
  '14' => %w[forky],
11
12
  '13' => %w[trixie],
12
13
  '12' => %w[bookworm],
@@ -33,6 +34,7 @@ module DebianCodename
33
34
  # Codename nouns ignored here at the moment but kept for consistency and possible future
34
35
  # improvements
35
36
  UBUNTU_CODENAMES = {
37
+ '@distribution' => 'ubuntu',
36
38
  '23.04' => %w[lunar lobster],
37
39
  '22.10' => %w[kinetic kudu],
38
40
  '22.04' => %w[jammy jellyfish],
@@ -73,18 +75,51 @@ module DebianCodename
73
75
 
74
76
  module_function
75
77
 
76
- # Whether version number or codename is the user_search_string, return the matching
77
- # item.
78
+ # Convert from version string to codename and vice versa
78
79
  def fast_find(user_search_string)
79
80
  search_string = user_search_string.downcase
80
81
 
81
82
  [DEBIAN_CODENAMES, UBUNTU_CODENAMES].each do |code_catalog|
82
- return code_catalog[search_string][0] if code_catalog.key?(search_string)
83
+ return codename(code_catalog, search_string) if code_catalog.key?(search_string)
83
84
 
84
- key = code_catalog.find { |_key, value| value[0] == search_string }
85
- return key.first unless key.nil?
85
+ version_found = code_catalog.find { |_, value| value[0] == search_string }
86
+ return version_found.first unless version_found.nil?
86
87
  end
87
88
 
88
89
  raise DebianCodenameError, "No match for #{user_search_string}"
89
90
  end
91
+
92
+ # Return a canonical form (Hash with ':version', ':codename', and ':distribution' keys)
93
+ def find(user_search_string)
94
+ search_string = user_search_string.downcase
95
+
96
+ [DEBIAN_CODENAMES, UBUNTU_CODENAMES].each do |code_catalog|
97
+ if code_catalog.key?(search_string)
98
+ return {
99
+ version: search_string,
100
+ codename: codename(code_catalog, search_string),
101
+ distribution: distribution(code_catalog)
102
+ }
103
+ end
104
+
105
+ version_found = code_catalog.find { |_, value| value[0] == search_string }
106
+ unless version_found.nil?
107
+ return {
108
+ version: version_found.first,
109
+ codename: search_string,
110
+ distribution: distribution(code_catalog)
111
+ }
112
+ end
113
+ end
114
+
115
+ raise DebianCodenameError, 'No match'
116
+ end
117
+
118
+ def codename(code_catalog, version_string)
119
+ code_catalog[version_string][0]
120
+ end
121
+
122
+ def distribution(code_catalog)
123
+ code_catalog['@distribution']
124
+ end
90
125
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: debian_codename
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet Release Engineering
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-05 00:00:00.000000000 Z
11
+ date: 2023-06-12 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Convert Debian/Ubuntu codenames to version numbers and vice-versa
14
14
  email: