Skip to content

Commit 3073f73

Browse files
author
qount25
committed
Fixing rubocop issues
1 parent 79e1172 commit 3073f73

File tree

10 files changed

+64
-78
lines changed

10 files changed

+64
-78
lines changed

exe/pgpm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ module Pgpm
109109
arch.with_scope do
110110
selected_pgdist.with_scope do
111111
spec = nil
112-
b = pkgs.reduce(nil) do |c, p|
112+
pkgs.reduce(nil) do |_c, p|
113113
p = Pgpm::ScopedObject.new(p, os, arch)
114114
spec = p.to_deb_spec
115115
end

lib/pgpm/deb/builder.rb

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# frozen_string_literal: true
22

3+
require "English"
34
require "debug"
45

56
module Pgpm
67
module Deb
78
class Builder
8-
99
def initialize(spec)
1010
@spec = spec
11-
@container_name = "pgpm-debian_build-#{Time.now.to_i}_#{rand(10000)}"
12-
@pgpm_dir = Dir.mktmpdir
11+
@container_name = "pgpm-debian_build-#{Time.now.to_i}_#{rand(10_000)}"
12+
@pgpm_dir = Dir.mktmpdir
1313
end
1414

1515
def build
@@ -47,16 +47,16 @@ def prepare_versioned_source
4747

4848
fn = nil
4949
@spec.sources.map do |src|
50-
srcfile = File.join("#{@pgpm_dir}", src.name)
50+
srcfile = File.join(@pgpm_dir.to_s, src.name)
5151
File.write(srcfile, src.read)
5252
fn = src.name
5353
end
5454

5555
system("tar -xf #{@pgpm_dir}/#{fn} -C #{@pgpm_dir}/source-versioned/")
5656
FileUtils.remove("#{@pgpm_dir}/#{fn}")
5757

58-
untar_dir_entries = Dir.entries("#{@pgpm_dir}/source-versioned/").select do |entry|
59-
!([".", ".."].include?(entry))
58+
untar_dir_entries = Dir.entries("#{@pgpm_dir}/source-versioned/").reject do |entry|
59+
[".", ".."].include?(entry)
6060
end
6161

6262
if untar_dir_entries.size == 1
@@ -68,11 +68,10 @@ def prepare_versioned_source
6868
end
6969
end
7070

71-
["prepare_artifacts.sh"].each do |fn|
72-
script_fn = File.expand_path("#{__dir__}/scripts/#{fn}")
71+
["prepare_artifacts.sh"].each do |f|
72+
script_fn = File.expand_path("#{__dir__}/scripts/#{f}")
7373
FileUtils.cp script_fn, "#{@pgpm_dir}/source-versioned/"
7474
end
75-
7675
end
7776

7877
def prepare_default_source
@@ -107,22 +106,22 @@ def pull_image
107106
puts "Checking if podman image exists..."
108107
# Check if image exists
109108
system("podman image exists #{image_name}")
110-
if $?.to_i > 0 # image doesn't exist -- pull image from a remote repository
109+
if $CHILD_STATUS.to_i.positive? # image doesn't exist -- pull image from a remote repository
111110
puts " No. Pulling image #{image_name}..."
112111
system("podman pull #{image_name}")
113112
else
114113
puts " Yes, image #{image_name} already exists! OK"
115114
end
116115
end
117116

118-
def generate_deb_src_files(pkg_type=:versioned)
117+
def generate_deb_src_files(pkg_type = :versioned)
119118
puts "Generating debian files..."
120119
Dir.mkdir "#{@pgpm_dir}/source-#{pkg_type}/debian"
121-
[:changelog, :control, :copyright, :files, :rules].each do |f|
120+
%i[changelog control copyright files rules].each do |f|
122121
puts " -> #{@pgpm_dir}/source-#{pkg_type}/debian/#{f}"
123122
File.write "#{@pgpm_dir}/source-#{pkg_type}/debian/#{f}", @spec.generate(f, pkg_type)
124123
end
125-
File.chmod 0740, "#{@pgpm_dir}/source-#{pkg_type}/debian/rules" # rules file must be executable
124+
File.chmod 0o740, "#{@pgpm_dir}/source-#{pkg_type}/debian/rules" # rules file must be executable
126125
end
127126

128127
def start_container
@@ -134,9 +133,9 @@ def start_container
134133

135134
puts " Creating and starting container #{@container_name} & running pbuilder"
136135
system("podman create -it #{create_opts}")
137-
exit(1) if $?.to_i > 0
136+
exit(1) if $CHILD_STATUS.to_i.positive?
138137
system("podman start #{@container_name}")
139-
exit(1) if $?.to_i > 0
138+
exit(1) if $CHILD_STATUS.to_i.positive?
140139
end
141140

142141
# Prevents clean-up after pbuilder finishes. There's no option
@@ -154,7 +153,7 @@ def patch_pbuilder
154153
system("podman exec #{@container_name} /bin/bash -c '#{cmd}'")
155154
end
156155

157-
def run_build(pkg_type=:versioned)
156+
def run_build(pkg_type = :versioned)
158157
dsc_fn = "#{@spec.deb_pkg_name(pkg_type)}_0-1.dsc"
159158
deb_fn = "#{@spec.deb_pkg_name(pkg_type)}_0-1_#{@spec.arch}.deb"
160159

@@ -166,11 +165,11 @@ def run_build(pkg_type=:versioned)
166165
puts " Building package with pbuilder..."
167166
cmds.each do |cmd|
168167
system("podman exec -w /root/pgpm/source-#{pkg_type} #{@container_name} /bin/bash -c '#{cmd}'")
169-
exit(1) if $?.to_i > 0
168+
exit(1) if $CHILD_STATUS.to_i.positive?
170169
end
171170
end
172171

173-
def copy_build_from_container(pkg_type=:versioned)
172+
def copy_build_from_container(pkg_type = :versioned)
174173
puts "Copying .deb file from podman container into current directory..."
175174
deb_fn = "#{@spec.deb_pkg_name(pkg_type)}_0-1_#{@spec.arch}.deb"
176175
deb_copy_fn = "#{@spec.deb_pkg_name(pkg_type)}_#{@spec.arch}.deb"
@@ -203,7 +202,6 @@ def selinux_enabled?
203202
# This returns true or false by itself
204203
system("sestatus | grep 'SELinux status' | grep -o 'enabled'")
205204
end
206-
207205
end
208206
end
209207
end

lib/pgpm/deb/spec.rb

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ def sources
2020
@package.sources
2121
end
2222

23-
def generate(template_name, pkg_type=:versioned)
23+
def generate(template_name, pkg_type = :versioned)
2424
fn = "#{__dir__}/templates/#{template_name}.erb"
2525
raise "No such template: #{fn}" unless File.exist?(fn)
26+
2627
erb = ERB.new(File.read(fn))
2728

2829
# Uses pkg_type parameter (which is in scope) to generate
@@ -32,10 +33,10 @@ def generate(template_name, pkg_type=:versioned)
3233

3334
def source_version
3435
v = @package.version.to_s
35-
v.match(/\Z\d+\.\d+\Z/) ? v + ".0" : v
36+
v.match(/\Z\d+\.\d+\Z/) ? "#{v}.0" : v
3637
end
3738

38-
def deb_pkg_name(type=:versioned)
39+
def deb_pkg_name(type = :versioned)
3940
if type == :versioned
4041
"#{@package.name.gsub("_", "-")}+#{source_version}-pg#{@package.postgres_major_version}"
4142
else
@@ -47,23 +48,20 @@ def arch
4748
# https://memgraph.com/blog/ship-it-on-arm64-or-is-it-aarch64
4849
# Debian suffixes are "amd64" and "arm64". Here we translate:
4950
case Pgpm::Arch.in_scope.name
50-
when "amd64", "x86_64"
51-
"amd64"
52-
when "aarch64", "arm64"
53-
"arm64"
51+
when "amd64", "x86_64"
52+
"amd64"
53+
when "aarch64", "arm64"
54+
"arm64"
5455
end
5556
end
5657

5758
def cmds_if_not_empty(cmds, else_echo)
58-
if cmds.nil? || cmds.empty?
59-
return "\techo \"#{else_echo}\""
60-
else
61-
cmds.map! { |c| c.to_s }
62-
cmds.map! { |c| c.gsub("$", "$$") }
63-
return cmds.join("\t")
64-
end
65-
end
59+
return "\techo \"#{else_echo}\"" if cmds.nil? || cmds.empty?
6660

61+
cmds.map!(&:to_s)
62+
cmds.map! { |c| c.gsub("$", "$$") }
63+
cmds.join("\t")
64+
end
6765
end
6866
end
6967
end

lib/pgpm/os/debian.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ def self.builder
2929
def mock_config
3030
"debian-12-#{Pgpm::Arch.in_scope.name}+pgdg"
3131
end
32-
3332
end
3433
end
3534
end

lib/pgpm/package/dependencies.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
module Pgpm
66
class Package
77
module Dependencies
8-
98
attr_accessor :postgres_major_version
109

1110
def build_dependencies
@@ -16,7 +15,7 @@ def build_dependencies
1615
"postgresql-server-dev-#{postgres_major_version}",
1716
"postgresql-common"
1817
]
19-
if self.native?
18+
if native?
2019
deps << "build-essential"
2120
end
2221
when "rocky+epel-9", "redhat", "fedora"
@@ -27,7 +26,7 @@ def build_dependencies
2726
def dependencies
2827
case Pgpm::OS.in_scope.class.name
2928
when "debian", "ubuntu"
30-
[ "postgresql-#{postgres_major_version}" ]
29+
["postgresql-#{postgres_major_version}"]
3130
when "rocky+epel-9", "redhat", "fedora"
3231
[]
3332
end
@@ -71,7 +70,6 @@ def sorted_packages
7170
def c_files_present?
7271
Dir.glob("*.c", base: source).any?
7372
end
74-
7573
end
7674
end
7775
end

lib/pgpm/package/make.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,19 @@
33
module Pgpm
44
class Package
55
module Make
6-
76
def build_steps
87
[Pgpm::Commands::Make.new("PG_CONFIG=$PG_CONFIG")] if makefile_present?
98
end
109

1110
def install_steps
12-
if makefile_present?
13-
[Pgpm::Commands::Make.new("install", "DESTDIR=$PGPM_INSTALL_ROOT", "PG_CONFIG=$PG_CONFIG")]
14-
end
11+
return unless makefile_present?
12+
13+
[Pgpm::Commands::Make.new("install", "DESTDIR=$PGPM_INSTALL_ROOT", "PG_CONFIG=$PG_CONFIG")]
1514
end
1615

1716
def makefile_present?
1817
!Dir.glob(%w[Makefile GNUmakefile makefile], base: source.to_s).empty?
1918
end
20-
2119
end
22-
2320
end
2421
end

lib/pgpm/package/packaging.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33
module Pgpm
44
class Package
55
module Packaging
6-
76
def to_rpm_spec(**opts)
87
Pgpm::RPM::Spec.new(self, **opts)
98
end
109

1110
def to_deb_spec(**opts)
1211
Pgpm::Deb::Spec.new(self, **opts)
1312
end
14-
1513
end
1614
end
1715
end

lib/pgpm/package/pgxn.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ def license
5858
end
5959

6060
def license_text
61-
path = "#{self.source.to_s}"
62-
["license", "lisence", "unlicense", "unlisence", "copying"].each do |fn|
61+
path = source.to_s
62+
%w[license lisence unlicense unlisence copying].each do |fn|
6363
[fn, fn.capitalize, fn.upcase].each do |fn2|
6464
["", ".txt", ".md"].each do |fn3|
6565
if File.exist?("#{path}/#{fn2}#{fn3}")
@@ -70,7 +70,6 @@ def license_text
7070
end
7171
nil
7272
end
73-
7473
end
7574
end
7675
end

packages/pgsodium.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ class Pgsodium < Pgpm::Package
44
github "michelp/pgsodium"
55

66
def build_dependencies
7-
deps = case Pgpm::OS.in_scope.class.name
8-
when "debian", "ubuntu"
9-
["libsodium-dev (>= 1.0.18)"]
10-
when "rocky+epel-9", "redhat", "fedora"
11-
["libsodium-devel >= 1.0.18"]
12-
end
13-
super + deps
7+
deps = case Pgpm::OS.in_scope.class.name
8+
when "debian", "ubuntu"
9+
["libsodium-dev (>= 1.0.18)"]
10+
when "rocky+epel-9", "redhat", "fedora"
11+
["libsodium-devel >= 1.0.18"]
12+
end
13+
super + deps
1414
end
1515

1616
def dependencies
1717
deps = case Pgpm::OS.in_scope.class.name
18-
when "debian", "ubuntu"
19-
["libsodium (>= 1.0.18)"]
20-
when "rocky+epel-9", "redhat", "fedora"
21-
["libsodium >= 1.0.18"]
22-
end
18+
when "debian", "ubuntu"
19+
["libsodium (>= 1.0.18)"]
20+
when "rocky+epel-9", "redhat", "fedora"
21+
["libsodium >= 1.0.18"]
22+
end
2323
super + deps
2424
end
2525

packages/timescale/timescaledb.rb

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,33 @@ def self.package_versions
1212
end
1313

1414
def description
15-
"An open-source time-series SQL database optimized for fast ingest and " +
16-
"complex queries"
15+
"An open-source time-series SQL database optimized for fast ingest and " \
16+
"complex queries"
1717
end
1818

1919
def summary
20-
"TimescaleDB is an open-source database designed to make SQL " +
21-
"scalable for time-series data. It is engineered up from PostgreSQL " +
22-
"and packaged as a PostgreSQL extension, providing automatic " +
23-
"partitioning across time and space (partitioning key), as well as " +
20+
"TimescaleDB is an open-source database designed to make SQL " \
21+
"scalable for time-series data. It is engineered up from PostgreSQL " \
22+
"and packaged as a PostgreSQL extension, providing automatic " \
23+
"partitioning across time and space (partitioning key), as well as " \
2424
"full SQL support."
2525
end
2626

2727
def dependencies
2828
deps = case Pgpm::OS.in_scope.class.name
29-
when "rocky+epel-9", "redhat", "fedora"
30-
["openssl"]
31-
end
29+
when "rocky+epel-9", "redhat", "fedora"
30+
["openssl"]
31+
end
3232
super + deps
3333
end
3434

3535
def build_dependencies
3636
deps = case Pgpm::OS.in_scope.class.name
37-
when "debian", "ubuntu"
38-
["libssl-dev", "cmake"]
39-
when "rocky+epel-9", "redhat", "fedora"
40-
["openssl-devel", "cmake"]
41-
end
37+
when "debian", "ubuntu"
38+
%w[libssl-dev cmake]
39+
when "rocky+epel-9", "redhat", "fedora"
40+
%w[openssl-devel cmake]
41+
end
4242
super + deps
4343
end
4444

@@ -77,6 +77,5 @@ def install_steps
7777
def bootstrap_flags
7878
[]
7979
end
80-
8180
end
8281
end

0 commit comments

Comments
 (0)