Skip to content

Commit d480b24

Browse files
committed
feat: add Ubuntu::ARCH, sort struct
Add missing top-level module Update testing
1 parent 3ac39a8 commit d480b24

File tree

8 files changed

+116
-52
lines changed

8 files changed

+116
-52
lines changed

lib/rootfs.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# frozen_string_literal: true
22

33
require_relative "rootfs/version"
4-
require_relative "rootfs/distro/ubuntu"
4+
require_relative "rootfs/distro"
55

66
module RootFS
7-
extend RootFS::Distro::Ubuntu
87
end

lib/rootfs/distro.rb

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "distro/ubuntu"
4+
5+
module RootFS
6+
module Distro
7+
end
8+
end

lib/rootfs/distro/ubuntu.rb

+4-47
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,12 @@
11
# frozen_string_literal: true
22

3+
require_relative "ubuntu/arch"
4+
require_relative "ubuntu/edition"
5+
require_relative "ubuntu/url"
6+
37
module RootFS
48
module Distro
59
module Ubuntu
6-
# https://ubuntu.com/download
7-
8-
# https://wiki.ubuntu.com/Releases
9-
# http://releases.ubuntu.com/
10-
# https://cloud-images.ubuntu.com/
11-
LTS = {
12-
jammy: "22.04",
13-
focal: "20.04",
14-
bionic: "18.04"
15-
}
16-
17-
ESM = {
18-
xenial: "16.04",
19-
trusty: "14.04"
20-
}
21-
22-
DEV = {
23-
lunar: "23.04",
24-
kinetic: "22.10"
25-
}
26-
27-
CODENAME_VERSION = {}.merge(DEV, LTS, ESM)
28-
29-
EDITION_RELEASE_URL = {
30-
Desktop: "http://cdimage.ubuntu.com/releases/",
31-
Server: "http://cdimage.ubuntu.com/releases/",
32-
Base: "http://cdimage.ubuntu.com/ubuntu-base/releases/",
33-
Cloud: "https://cloud-images.ubuntu.com/releases/",
34-
Minimal: "https://cloud-images.ubuntu.com/minimal/releases/"
35-
}
36-
37-
EDITION_DAILY_URL = {
38-
Desktop: "http://cdimage.ubuntu.com/",
39-
Server: "http://cdimage.ubuntu.com/ubuntu-server/",
40-
Base: "http://cdimage.ubuntu.com/ubuntu-base/",
41-
Cloud: "https://cloud-images.ubuntu.com/",
42-
Minimal: "https://cloud-images.ubuntu.com/minimal/daily/"
43-
}
44-
45-
def is_lts?(any)
46-
str = any.to_s
47-
LTS.each do |code, ver|
48-
return true if str == code.to_s
49-
return true if str.start_with?(ver)
50-
end
51-
false
52-
end
5310
end
5411
end
5512
end

lib/rootfs/distro/ubuntu/arch.rb

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# frozen_string_literal: true
2+
3+
module RootFS
4+
module Distro
5+
module Ubuntu
6+
ARCH = %w[
7+
amd64
8+
arm64
9+
armhf
10+
pp64el
11+
riscv64
12+
s390x
13+
].freeze
14+
end
15+
end
16+
end

lib/rootfs/distro/ubuntu/edition.rb

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# frozen_string_literal: true
2+
3+
module RootFS
4+
module Distro
5+
module Ubuntu
6+
# https://ubuntu.com/download
7+
8+
# https://wiki.ubuntu.com/Releases
9+
# http://releases.ubuntu.com/
10+
# https://cloud-images.ubuntu.com/
11+
12+
LTS = {
13+
jammy: "22.04",
14+
focal: "20.04",
15+
bionic: "18.04"
16+
}.freeze
17+
18+
ESM = {
19+
xenial: "16.04",
20+
trusty: "14.04"
21+
}.freeze
22+
23+
DEV = {
24+
lunar: "23.04",
25+
kinetic: "22.10"
26+
}.freeze
27+
28+
CODENAME_VERSION = {}.merge(DEV, LTS, ESM).freeze
29+
30+
def lts?(any)
31+
str = any.to_s
32+
LTS.each do |code, ver|
33+
return true if str == code.to_s
34+
return true if str.start_with?(ver)
35+
end
36+
false
37+
end
38+
end
39+
end
40+
end

lib/rootfs/distro/ubuntu/url.rb

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# frozen_string_literal: true
2+
3+
module RootFS
4+
module Distro
5+
module Ubuntu
6+
# https://ubuntu.com/download
7+
8+
# https://wiki.ubuntu.com/Releases
9+
# http://releases.ubuntu.com/
10+
# https://cloud-images.ubuntu.com/
11+
12+
EDITION_RELEASE_URL = {
13+
Desktop: "http://cdimage.ubuntu.com/releases/",
14+
Server: "http://cdimage.ubuntu.com/releases/",
15+
Base: "http://cdimage.ubuntu.com/ubuntu-base/releases/",
16+
Cloud: "https://cloud-images.ubuntu.com/releases/",
17+
Minimal: "https://cloud-images.ubuntu.com/minimal/releases/"
18+
}.freeze
19+
20+
EDITION_DAILY_URL = {
21+
Desktop: "http://cdimage.ubuntu.com/",
22+
Server: "http://cdimage.ubuntu.com/ubuntu-server/",
23+
Base: "http://cdimage.ubuntu.com/ubuntu-base/",
24+
Cloud: "https://cloud-images.ubuntu.com/",
25+
Minimal: "https://cloud-images.ubuntu.com/minimal/daily/"
26+
}.freeze
27+
end
28+
end
29+
end

lib/rootfs/distro/ubuntu_test.rb

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,9 @@ class MyClass
99

1010
u = MyClass.new
1111

12-
p u.is_lts?("20.04.5")
13-
p MyClass::CODENAME_VERSION
12+
p u.lts?("focal")
13+
p u.lts?("20.04.5")
14+
p u.lts?("20.04")
15+
p u.lts?("20")
16+
p u.lts?("20.10")
17+
p MyClass::CODENAME_VERSION

spec/distro/ubuntu_spec.rb

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
# frozen_string_literal: true
22

33
RSpec.describe RootFS do
4+
class MyClass
5+
extend RootFS::Distro::Ubuntu
6+
include RootFS::Distro::Ubuntu
7+
end
8+
9+
u = MyClass.new
10+
11+
it "does something useful" do
12+
expect(MyClass.lts?(20.04)).to eq(true)
13+
end
14+
415
it "does something useful" do
5-
expect(RootFS.is_lts?(20.04)).to eq(true)
16+
expect(u.lts?(20.04)).to eq(true)
617
end
718
end

0 commit comments

Comments
 (0)