compact_index 0.3.1 → 0.4.1

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: e6492761458b50fdbcb83b689108a86cb615a92d
4
- data.tar.gz: 004af9c6c3d5ab2d3b34d31681a3e37eceaacabd
3
+ metadata.gz: bbd6a30b0d60a7d08b00d9d46e06c277995840cf
4
+ data.tar.gz: 7afb08dbfa5fcc801aac009bb2153fab50a8ff6b
5
5
  SHA512:
6
- metadata.gz: 80543b634e539cc4027c0242b156416f4ca24d810ce62357808d30c3a8fa58547a4459016695fd7593d574b1a3d1a26e2af47bf0e38b634d82f3b7988c6e1d67
7
- data.tar.gz: 65230c95d25f3f4c51f0caf6805cd516ed51c67b6dd6a2e82179fb569fb607cda69d8e1ab89e0eed3e97708ae80b7435da593cacf98eb242c76526560e4ef9b1
6
+ metadata.gz: aeb75821bbec6205ddaf38aed73d4552e7e1f7d11889cf7f9f6cf4e9981f12ebe7e51a9c5e822d62d165922f6c9ab8dc2fa44ef66a26ffa272fdd251e43577f1
7
+ data.tar.gz: 900911a7cbef27e3602158d148257ecc60fa5e016983ecd668f1a92ac43299e2f39662f01ccf6ffc6b6a71103a9f0c82bf1a0904c9d475d6e7ebdc4fc633b9fa
@@ -1,5 +1,4 @@
1
1
  language: ruby
2
2
  rvm: 2.1.5
3
3
  script: bundle exec rspec
4
- before_script: cp spec/config.yml.example spec/config.yml
5
4
 
@@ -18,8 +18,6 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "sequel"
22
- spec.add_dependency "pg"
23
21
  spec.add_development_dependency "rake", "~> 10.0"
24
22
  spec.add_development_dependency "rspec", "~> 3"
25
23
  end
@@ -1,6 +1,5 @@
1
1
  require "compact_index/version"
2
2
  require "compact_index/versions_file"
3
- require "compact_index/gem_info"
4
3
 
5
4
  module CompactIndex
6
5
  def self.names(gem_names)
@@ -14,16 +13,16 @@ module CompactIndex
14
13
  def self.info(params)
15
14
  output = "---\n"
16
15
  params.each do |version|
17
- output << version_line(version[:number], version[:dependencies]) << "\n"
16
+ output << version_line(version) << "\n"
18
17
  end
19
18
  output
20
19
  end
21
20
 
22
21
  private
23
- def self.version_line(version, dependencies = nil)
24
- if dependencies
25
- dependencies.sort! { |a,b| a[:gem] <=> b[:gem] }
26
- deps = dependencies.map do |d|
22
+ def self.version_line(version)
23
+ if version[:dependencies]
24
+ version[:dependencies].sort! { |a,b| a[:gem] <=> b[:gem] }
25
+ deps = version[:dependencies].map do |d|
27
26
  [
28
27
  d[:gem],
29
28
  d[:version].gsub(/, /, "&")
@@ -33,8 +32,16 @@ module CompactIndex
33
32
  deps = []
34
33
  end
35
34
 
36
- line = version
35
+ line = version[:number]
37
36
  line << " " << deps.join(",") if deps.any?
37
+ line << "|"
38
+
39
+ after_pipe = []
40
+ after_pipe << "checksum:#{version[:checksum]}"
41
+ after_pipe << "ruby:#{version[:ruby_version]}" if version[:ruby_version]
42
+ after_pipe << "rubygems:#{version[:rubygems_version]}" if version[:rubygems_version]
43
+ line << after_pipe.join(",")
44
+
38
45
  line
39
46
  end
40
47
  end
@@ -1,3 +1,3 @@
1
1
  module CompactIndex
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -8,7 +8,7 @@ class CompactIndex::VersionsFile
8
8
  def create(gems)
9
9
  content = "created_at: #{Time.now.iso8601}"
10
10
  content += "\n---\n"
11
- content += parse_gems(gems)
11
+ content += parse_gems_for_create(gems)
12
12
 
13
13
  File.open(@path, 'w') do |io|
14
14
  io.write content
@@ -34,6 +34,16 @@ class CompactIndex::VersionsFile
34
34
 
35
35
  private
36
36
 
37
+
38
+ def parse_gems_for_create(gems)
39
+ fixed_format_gems = gems.map do |k,v|
40
+ numbers = v.map { |x| x[:number] }
41
+ { name: k, versions: numbers, checksum: v.first[:checksum] }
42
+ end
43
+ fixed_format_gems.sort! { |a,b| a[:name] <=> b[:name] }
44
+ gem_lines(fixed_format_gems)
45
+ end
46
+
37
47
  def parse_gems(gems)
38
48
  sorted_gems = format_by_created_time(gems)
39
49
  gem_lines(sorted_gems)
@@ -41,16 +51,19 @@ class CompactIndex::VersionsFile
41
51
 
42
52
  def format_by_created_time(gems)
43
53
  by_created_at = {}
54
+ checksums = {}
44
55
  gems.each do |name, versions|
45
56
  versions.each do |v|
46
57
  by_created_at[v[:created_at]] ||= {}
47
58
  by_created_at[v[:created_at]][name] ||= []
48
59
  by_created_at[v[:created_at]][name] << v[:number]
60
+ checksums[v[:created_at]] ||= {}
61
+ checksums[v[:created_at]] = v[:checksum]
49
62
  end
50
63
  end
51
- by_created_at.sort.map do |_,gems|
64
+ by_created_at.sort.map do |created_at,gems|
52
65
  gems.map do |name, versions|
53
- { name: name, versions: versions }
66
+ { name: name, versions: versions, checksum: checksums[created_at] }
54
67
  end
55
68
  end.flatten
56
69
  end
@@ -58,7 +71,7 @@ class CompactIndex::VersionsFile
58
71
  def gem_lines(gems)
59
72
  gems.reduce("") do |concat, entry|
60
73
  versions = sort_versions(entry[:versions])
61
- concat + "#{entry[:name]} #{versions.join(',')}\n"
74
+ concat + "#{entry[:name]} #{versions.join(',')} #{entry[:checksum]}\n"
62
75
  end
63
76
  end
64
77
 
metadata CHANGED
@@ -1,43 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: compact_index
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.1
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-07-06 00:00:00.000000000 Z
11
+ date: 2015-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: sequel
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: pg
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
13
  - !ruby/object:Gem::Dependency
42
14
  name: rake
43
15
  requirement: !ruby/object:Gem::Requirement
@@ -92,7 +64,6 @@ files:
92
64
  - db/migrations/06_add_created_at_to_versions.rb
93
65
  - db/migrations/07_add_checksum_to_versions.rb
94
66
  - lib/compact_index.rb
95
- - lib/compact_index/gem_info.rb
96
67
  - lib/compact_index/version.rb
97
68
  - lib/compact_index/versions_file.rb
98
69
  homepage: https://github.com/bundler/compact_index
@@ -1,91 +0,0 @@
1
- require 'compact_index'
2
-
3
- # Return data about all the gems: all gem names, all versions of all gems, all dependencies for all versions of a gem
4
- class CompactIndex::GemInfo
5
- DepKey = Struct.new(:name, :number, :platform, :required_ruby_version, :rubygems_version, :checksum)
6
-
7
- def initialize(connection)
8
- @conn = connection
9
- end
10
-
11
- # @param [String] array of strings with the gem names
12
- def deps_for(gems = [])
13
- dataset =
14
- if gems.any?
15
- @conn[<<-SQL, Sequel.value_list(gems)]
16
- SELECT rv.name, rv.number, rv.platform, rv.required_ruby_version, rv.checksum,
17
- rv.rubygems_version, d.requirements, for_dep_name.name dep_name
18
- FROM
19
- (SELECT r.name, v.number, v.platform,v.rubygems_version, v.checksum,
20
- v.required_ruby_version, v.id AS version_id
21
- FROM rubygems AS r, versions AS v
22
- WHERE v.rubygem_id = r.id
23
- AND v.indexed is true
24
- AND r.name IN ?) AS rv
25
- LEFT JOIN dependencies AS d ON
26
- d.version_id = rv.version_id
27
- LEFT JOIN rubygems AS for_dep_name ON
28
- d.rubygem_id = for_dep_name.id
29
- AND d.scope = 'runtime';
30
- SQL
31
- else
32
- @conn[<<-SQL]
33
- SELECT rv.name, rv.number, rv.platform, d.requirements, for_dep_name.name dep_name
34
- FROM
35
- (SELECT r.name, v.number, v.platform, v.id AS version_id
36
- FROM rubygems AS r, versions AS v
37
- WHERE v.rubygem_id = r.id
38
- AND v.indexed is true) AS rv
39
- LEFT JOIN dependencies AS d ON
40
- d.version_id = rv.version_id
41
- LEFT JOIN rubygems AS for_dep_name ON
42
- d.rubygem_id = for_dep_name.id
43
- AND d.scope = 'runtime';
44
- SQL
45
- end
46
-
47
- deps = {}
48
-
49
- dataset.each do |row|
50
- key = DepKey.new(row[:name], row[:number], row[:platform], row[:required_ruby_version], row[:rubygems_version], row[:checksum])
51
- deps[key] = [] unless deps[key]
52
- deps[key] << [row[:dep_name], row[:requirements]] if row[:dep_name]
53
- end
54
-
55
- deps.map do |dep_key, gem_deps|
56
- {
57
- name: dep_key.name,
58
- number: dep_key.number,
59
- platform: dep_key.platform,
60
- rubygems_version: dep_key.rubygems_version,
61
- required_ruby_version: dep_key.required_ruby_version,
62
- checksum: dep_key.checksum,
63
- dependencies: gem_deps
64
- }
65
- end
66
- end
67
-
68
- # return list of gem names
69
- def names
70
- @conn[:rubygems].select(:name).order(:name).all.map {|r| r[:name] }
71
- end
72
-
73
- # return a list of gem names and their versions
74
- def versions
75
- specs_hash = Hash.new {|h, k| h[k] = [] }
76
- rows = @conn[<<-SQL]
77
- SELECT v.full_name, v.number, v.platform
78
- FROM versions AS v
79
- WHERE v.indexed is true
80
- SQL
81
- rows.each do |row|
82
- full_name = row[:full_name]
83
- version = row[:number]
84
- version += "-" << row[:platform] unless row[:platform] == "ruby"
85
- name = full_name.chomp("-" << version)
86
- specs_hash[name] << version
87
- end
88
-
89
- specs_hash.each {|k, v| v.sort! }
90
- end
91
- end