From 1595078be364e358eb5240071f643cf433ad7766 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20=C4=8Cerm=C3=A1k?= <45594031+dcermak@users.noreply.github.com> Date: Thu, 7 Jul 2022 12:21:31 +0200 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Ewoud Kohl van Wijngaarden --- bin/gem2rpm | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/bin/gem2rpm b/bin/gem2rpm index 3b07dbd..c63532c 100755 --- a/bin/gem2rpm +++ b/bin/gem2rpm @@ -27,14 +27,9 @@ end rest = options[:args] template = nil -if template_file.nil? - f = open('/etc/os-release', 'r') if File.exists?('/etc/os-release') - if f - f.read.split('\n').each do |line| - line.match(%r{^ID=(.*)$}) { |m| template_file=m[1] } - end - f.close - f = nil +if template_file.nil? && File.exist?('/etc/os-release') + File.read('/etc/os-release').each_line(chomp: true) do |line| + line.match(%r{^ID=(.*)$}) { |m| template_file=m[1] } end if template_file.match? '^"opensuse' $stderr.puts 'Using template opensuse on openSUSE variant' @@ -44,15 +39,13 @@ end if template_file.nil? template = Gem2Rpm::TEMPLATE else + template_file = File.join(Gem2Rpm.template_dir, template_file + '.spec.erb') unless File.exist?(template_file) begin - f = open(template_file, 'r') if File.exists?(template_file) - f = open(File.join(Gem2Rpm.template_dir, template_file + '.spec.erb'), 'r') unless f + template = File.read(template_file) rescue Errno::ENOENT $stderr.puts "Could not open template #{template_file}. Aborting" exit(1) end - template = f.read - f.close end if options[:print_template_file]