compact_index 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/lib/compact_index.rb +20 -13
- data/lib/compact_index/version.rb +1 -1
- data/lib/compact_index/versions_file.rb +43 -49
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87fc1665041ba2af025514fe237e33f96889d2e2
|
4
|
+
data.tar.gz: 9e207f65d64a0a52873c75689f32d4711b5066bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d30ee18ae3e651d79c980c211dac350c72c73ab34df3ce814b3aa1c42a21ea3a6f0768cebbd7d8119f1522bc8a48305639514861fbe15875efa645c840ec121
|
7
|
+
data.tar.gz: 2e3cf006537b2575f19558a815e9126f5fa4d08b23bd5f19001415449c7cfc1f668a69d812ea30d434877150cc6c9047b3ecd73319344cf694082da6c3a246a2
|
data/.gitignore
CHANGED
data/lib/compact_index.rb
CHANGED
@@ -3,31 +3,38 @@ require "compact_index/versions_file"
|
|
3
3
|
require "compact_index/gem_info"
|
4
4
|
|
5
5
|
module CompactIndex
|
6
|
-
def self.names(
|
7
|
-
"---\n" +
|
6
|
+
def self.names(gem_names)
|
7
|
+
"---\n" + gem_names.join("\n") + "\n"
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.versions(
|
11
|
-
VersionsFile.new(
|
10
|
+
def self.versions(path, gems)
|
11
|
+
versions_file = VersionsFile.new(path)
|
12
|
+
versions_file.contents(gems)
|
12
13
|
end
|
13
14
|
|
14
|
-
def self.info(
|
15
|
+
def self.info(params)
|
15
16
|
output = "---\n"
|
16
|
-
|
17
|
-
|
18
|
-
output << version_line(row) << "\n"
|
17
|
+
params.each do |version|
|
18
|
+
output << version_line(version[:number], version[:dependencies]) << "\n"
|
19
19
|
end
|
20
20
|
output
|
21
21
|
end
|
22
22
|
|
23
23
|
private
|
24
|
-
def self.version_line(
|
25
|
-
|
26
|
-
|
24
|
+
def self.version_line(version, dependencies = nil)
|
25
|
+
if dependencies
|
26
|
+
dependencies.sort! { |a,b| a[:gem] <=> b[:gem] }
|
27
|
+
deps = dependencies.map do |d|
|
28
|
+
[
|
29
|
+
d[:gem],
|
30
|
+
d[:version].gsub(/, /, "&")
|
31
|
+
].join
|
32
|
+
end
|
33
|
+
else
|
34
|
+
deps = []
|
27
35
|
end
|
28
36
|
|
29
|
-
line =
|
30
|
-
line << "-#{row[:platform]}" unless row[:platform] == "ruby"
|
37
|
+
line = version
|
31
38
|
line << " " << deps.join(",") if deps.any?
|
32
39
|
line
|
33
40
|
end
|
@@ -1,76 +1,70 @@
|
|
1
1
|
require 'compact_index'
|
2
2
|
|
3
3
|
class CompactIndex::VersionsFile
|
4
|
-
|
5
|
-
|
6
|
-
@conn = connection
|
4
|
+
def initialize(file = nil)
|
5
|
+
@path = file || "/versions.list"
|
7
6
|
end
|
8
7
|
|
9
|
-
def
|
10
|
-
if File.exists? PATH
|
11
|
-
update
|
12
|
-
else
|
13
|
-
create
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def create
|
8
|
+
def create(gems)
|
18
9
|
content = "created_at: #{Time.now.iso8601}"
|
19
10
|
content += "\n---\n"
|
20
|
-
content +=
|
11
|
+
content += parse_gems(gems)
|
21
12
|
|
22
|
-
File.open(
|
13
|
+
File.open(@path, 'w') do |io|
|
23
14
|
io.write content
|
24
15
|
end
|
25
16
|
end
|
26
17
|
|
27
|
-
def update
|
28
|
-
|
29
|
-
|
30
|
-
io.write to_write
|
18
|
+
def update(gems)
|
19
|
+
File.open(@path, 'a') do |io|
|
20
|
+
io.write parse_gems(gems)
|
31
21
|
end
|
32
22
|
end
|
33
23
|
|
34
|
-
def
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
content + "\n" + new_gems
|
39
|
-
end
|
24
|
+
def contents(gems=nil)
|
25
|
+
out = File.open(@path).read
|
26
|
+
out += parse_gems(gems) if gems
|
27
|
+
out
|
40
28
|
end
|
41
29
|
|
30
|
+
def updated_at
|
31
|
+
DateTime.parse(File.mtime(@path).to_s)
|
32
|
+
end
|
33
|
+
|
34
|
+
|
42
35
|
private
|
43
|
-
def content
|
44
|
-
File.open(PATH).read
|
45
36
|
|
37
|
+
def parse_gems(gems)
|
38
|
+
sorted_gems = format_by_created_time(gems)
|
39
|
+
gem_lines(sorted_gems)
|
46
40
|
end
|
47
41
|
|
48
|
-
def
|
49
|
-
|
42
|
+
def format_by_created_time(gems)
|
43
|
+
by_created_at = {}
|
44
|
+
gems.each do |gem|
|
45
|
+
gem[:versions].each do |v|
|
46
|
+
by_created_at[v[:created_at]] ||= {}
|
47
|
+
by_created_at[v[:created_at]][gem[:name]] ||= []
|
48
|
+
by_created_at[v[:created_at]][gem[:name]] << v[:number]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
by_created_at.sort.map do |_,gems|
|
52
|
+
gems.map do |name, versions|
|
53
|
+
{ name: name, versions: versions }
|
54
|
+
end
|
55
|
+
end.flatten
|
50
56
|
end
|
51
57
|
|
52
|
-
def
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
ORDER BY number ASC
|
58
|
-
)
|
59
|
-
FROM rubygems AS r, versions AS v
|
60
|
-
WHERE v.rubygem_id = r.id AND
|
61
|
-
v.indexed is true
|
62
|
-
GROUP BY r.name
|
63
|
-
SQL
|
64
|
-
dataset.map { |entry| "#{entry[:name]} #{entry[:string_agg]}" }.join("\n")
|
58
|
+
def gem_lines(gems)
|
59
|
+
gems.reduce("") do |concat, entry|
|
60
|
+
versions = sort_versions(entry[:versions])
|
61
|
+
concat + "#{entry[:name]} #{versions.join(',')}\n"
|
62
|
+
end
|
65
63
|
end
|
66
64
|
|
67
|
-
def
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
WHERE v.rubygem_id = r.id AND v.indexed is true AND v.created_at > ?
|
72
|
-
ORDER BY v.created_at, r.name, concat_ws
|
73
|
-
SQL
|
74
|
-
dataset.map { |entry| "#{entry[:name]} #{entry[:concat_ws]}" }.join("\n")
|
65
|
+
def sort_versions(versions)
|
66
|
+
versions.sort do |a,b|
|
67
|
+
gem_comp = Gem::Version.new(a) <=> Gem::Version.new(b)
|
68
|
+
end
|
75
69
|
end
|
76
70
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: compact_index
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- fotanus@gmail.com
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06
|
11
|
+
date: 2015-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|