Skip to content

Commit 341f7ff

Browse files
indirectsonalkr132
authored andcommitted
move version_line into GemVersion
1 parent 1256627 commit 341f7ff

File tree

2 files changed

+20
-32
lines changed

2 files changed

+20
-32
lines changed

lib/compact_index.rb

+3-32
Original file line numberDiff line numberDiff line change
@@ -69,38 +69,9 @@ def self.versions(versions_file, gems = nil, args = {})
6969
# 1.0.1 requirement:<2.0&>1.0|checksum:abc1
7070
# 1.0.2 requirement:<2.0&>1.0,requirement2:=1.1|checksum:abc2,ruby:>1.0,rubygems:>2.0
7171
# ```
72-
def self.info(params)
73-
output = String.new("---\n")
74-
params.each do |version|
75-
output << version_line(version) << "\n"
72+
def self.info(versions)
73+
versions.inject("---\n") do |output, version|
74+
output << version.to_line << "\n"
7675
end
77-
output
78-
end
79-
80-
private
81-
82-
def self.version_line(version)
83-
if version[:dependencies]
84-
version[:dependencies]
85-
deps = version[:dependencies].map do |d|
86-
[
87-
d[:gem],
88-
d.version_and_platform.split(", ").sort.join("&")
89-
].join(":")
90-
end
91-
else
92-
deps = []
93-
end
94-
95-
line = version.number_and_platform.dup
96-
line << " "
97-
line << deps.join(",")
98-
line << "|"
99-
100-
line << "checksum:#{version[:checksum]}"
101-
line << ",ruby:#{version[:ruby_version]}" if version[:ruby_version]
102-
line << ",rubygems:#{version[:rubygems_version]}" if version[:rubygems_version]
103-
104-
line
10576
end
10677
end

lib/compact_index/gem_version.rb

+17
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,22 @@ def number_and_platform
99
"#{number}-#{platform}"
1010
end
1111
end
12+
13+
def to_line
14+
line = number_and_platform << " " << deps_line << "|checksum:#{checksum}"
15+
line << ",ruby:#{ruby_version}" if ruby_version && ruby_version != ">= 0"
16+
line << ",rubygems:#{rubygems_version}" if rubygems_version && rubygems_version != ">= 0"
17+
line
18+
end
19+
20+
private
21+
22+
def deps_line
23+
return "" if dependencies.nil?
24+
dependencies.map do |d|
25+
[d[:gem], d.version_and_platform.split(", ").sort.join("&")].join(":")
26+
end.join(",")
27+
end
28+
1229
end
1330
end

0 commit comments

Comments
 (0)