Skip to content

Commit

Permalink
refactor: apply rubocop suggestions to Ruby generator (#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Dec 19, 2023
1 parent 1b795b8 commit 877ad29
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions generators/generate-rubygems-versions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# such comparisons in the detector would in fact be wrong.
#
# @type [Array<String>]
UNSUPPORTED_COMPARISONS = []
UNSUPPORTED_COMPARISONS = [].freeze

# @param [String] line
# @return [Boolean]
Expand All @@ -24,12 +24,12 @@ def is_unsupported_comparison?(line)
# @param [String] line
# @return [String]
def uncomment(line)
line.sub(/^#|\/\//, "")
line.sub(%r{^#|//}, "")
end

def download_rubygems_db
URI.open("https://osv-vulnerabilities.storage.googleapis.com/RubyGems/all.zip") do |zip|
File.open("rubygems-db.zip", "wb") { |f| f.write(zip.read) }
File.binwrite("rubygems-db.zip", zip.read)
end
end

Expand All @@ -47,7 +47,7 @@ def extract_packages_with_versions(osvs)
end
end

packages.map { |k, v| [k, v.uniq.sort] }.to_h
packages.transform_values { |v| v.uniq.sort }
end

def compare_version(v1, op, v2)
Expand All @@ -72,7 +72,7 @@ def compare_versions(lines, select = :all)
next
end

parts = line.split(" ")
parts = line.split
v1 = parts[0]
op = parts[1]
v2 = parts[2]
Expand Down Expand Up @@ -117,15 +117,15 @@ def generate_version_compares(versions)
def generate_package_compares(packages)
comparisons = []

packages.each { |_, versions| comparisons.concat(generate_version_compares(versions)) }
packages.each_value { |versions| comparisons.concat(generate_version_compares(versions)) }

comparisons
end

def fetch_packages_versions
download_rubygems_db

osvs = Zip::File.open("rubygems-db.zip").map { |f| JSON.load(f.get_input_stream.read) }
osvs = Zip::File.open("rubygems-db.zip").map { |f| JSON.parse(f.get_input_stream.read) }

extract_packages_with_versions(osvs)
end
Expand All @@ -134,7 +134,7 @@ def fetch_packages_versions

packs = fetch_packages_versions

File.open(outfile, "w") { |f| f.write(generate_package_compares(packs).uniq.join("\n") + "\n") }
File.write(outfile, "#{generate_package_compares(packs).uniq.join("\n")}\n")

# set this to either "failures" or "successes" to only have those comparison results
# printed; setting it to anything else will have all comparison results printed
Expand Down

0 comments on commit 877ad29

Please sign in to comment.