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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 057af6bb8ef8c7251c6d7d22fc714db46285cd9e
4
- data.tar.gz: 3ef2a4c6081ca4c61e1f730a8b68e6e6081d7ae2
3
+ metadata.gz: 87fc1665041ba2af025514fe237e33f96889d2e2
4
+ data.tar.gz: 9e207f65d64a0a52873c75689f32d4711b5066bd
5
5
  SHA512:
6
- metadata.gz: 9d7c04c51b9d424f2aa36d2c8b7d30b130c91d39fca80667ea75e561b03499279bb3e4cd5a264fd725c214712a11638c233ad31ce9c4512b415546152cb94314
7
- data.tar.gz: b972136984bfe3e5f3fb5b4d835a0816166d37457c473552ea81e49a9a2b91ddffc8dd182593e8338c32a514e894d7c5e78d6013a9d019113f158292d06cadf0
6
+ metadata.gz: 6d30ee18ae3e651d79c980c211dac350c72c73ab34df3ce814b3aa1c42a21ea3a6f0768cebbd7d8119f1522bc8a48305639514861fbe15875efa645c840ec121
7
+ data.tar.gz: 2e3cf006537b2575f19558a815e9126f5fa4d08b23bd5f19001415449c7cfc1f668a69d812ea30d434877150cc6c9047b3ecd73319344cf694082da6c3a246a2
data/.gitignore CHANGED
@@ -7,4 +7,3 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
- spec/config.yml
@@ -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(conn)
7
- "---\n" + GemInfo.new(conn).names.join("\n") + "\n"
6
+ def self.names(gem_names)
7
+ "---\n" + gem_names.join("\n") + "\n"
8
8
  end
9
9
 
10
- def self.versions(conn)
11
- VersionsFile.new(conn).with_new_gems
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(conn, name)
15
+ def self.info(params)
15
16
  output = "---\n"
16
- name = [name] if name.kind_of? String
17
- GemInfo.new(conn).deps_for(name).each do |row|
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(row)
25
- deps = row[:dependencies].map do |d|
26
- [d.first, d.last.gsub(/, /, "&")].join(":")
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 = row[:number].to_s
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,3 +1,3 @@
1
1
  module CompactIndex
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -1,76 +1,70 @@
1
1
  require 'compact_index'
2
2
 
3
3
  class CompactIndex::VersionsFile
4
- PATH = "versions.list"
5
- def initialize(connection)
6
- @conn = connection
4
+ def initialize(file = nil)
5
+ @path = file || "/versions.list"
7
6
  end
8
7
 
9
- def create_or_update
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 += gems_for_new_file
11
+ content += parse_gems(gems)
21
12
 
22
- File.open(PATH, 'w') do |io|
13
+ File.open(@path, 'w') do |io|
23
14
  io.write content
24
15
  end
25
16
  end
26
17
 
27
- def update
28
- to_write = with_new_gems
29
- File.open(PATH, 'w') do |io|
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 with_new_gems
35
- if new_gems.empty?
36
- content
37
- else
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 created_at
49
- DateTime.parse(File.mtime(PATH).to_s)
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 gems_for_new_file
53
- dataset = @conn[<<-SQL]
54
- SELECT
55
- r.name, string_agg(
56
- concat_ws('-', v.number, nullif(v.platform,'ruby')), ','
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 new_gems
68
- dataset = @conn[<<-SQL, created_at]
69
- SELECT r.name, concat_ws('-', v.number, nullif(v.platform,'ruby'))
70
- FROM rubygems AS r, versions AS v
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.2.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-27 00:00:00.000000000 Z
11
+ date: 2015-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel