compact_index 0.9.4 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Sequel.migration do
2
4
  change do
3
5
  create_table :checksums do
@@ -5,7 +7,7 @@ Sequel.migration do
5
7
  String :name
6
8
  String :md5
7
9
 
8
- index [:name], name: :index_checksums_on_name, unqiue: true
10
+ index [:name], :name => :index_checksums_on_name, :unqiue => true
9
11
  end
10
12
  end
11
13
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Sequel.migration do
2
4
  change do
3
5
  alter_table :versions do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Sequel.migration do
2
4
  change do
3
5
  alter_table :versions do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "compact_index/gem"
2
4
  require "compact_index/gem_version"
3
5
  require "compact_index/dependency"
@@ -17,7 +19,7 @@ module CompactIndex
17
19
  # other-gem
18
20
  # ```
19
21
  def self.names(gem_names)
20
- "---\n" << gem_names.join("\n") << "\n"
22
+ String.new("---\n") << gem_names.join("\n") << "\n"
21
23
  end
22
24
 
23
25
  # Returns the versions file content argumented with some extra gems
@@ -48,7 +50,6 @@ module CompactIndex
48
50
  versions_file.contents(gems, args)
49
51
  end
50
52
 
51
-
52
53
  # Formats the versions information of a gem, to be display in the `/info/gemname` endpoint.
53
54
  #
54
55
  # @param versions_file [CompactIndex::VersionsFile] which will be used as a base response
@@ -69,40 +70,9 @@ module CompactIndex
69
70
  # 1.0.1 requirement:<2.0&>1.0|checksum:abc1
70
71
  # 1.0.2 requirement:<2.0&>1.0,requirement2:=1.1|checksum:abc2,ruby:>1.0,rubygems:>2.0
71
72
  # ```
72
- def self.info(params)
73
- output = "---\n"
74
- params.each do |version|
75
- output << version_line(version) << "\n"
73
+ def self.info(versions)
74
+ versions.inject("---\n".dup) do |output, version|
75
+ output << version.to_line << "\n"
76
76
  end
77
- output
78
- end
79
-
80
-
81
- private
82
-
83
-
84
- def self.version_line(version)
85
- if version[:dependencies]
86
- version[:dependencies]
87
- deps = version[:dependencies].map do |d|
88
- [
89
- d[:gem],
90
- d.version_and_platform.split(', ').sort.join("&")
91
- ].join(':')
92
- end
93
- else
94
- deps = []
95
- end
96
-
97
- line = version.number_and_platform
98
- line << " "
99
- line << deps.join(",")
100
- line << "|"
101
-
102
- line << "checksum:#{version[:checksum]}"
103
- line << ",ruby:#{version[:ruby_version]}" if version[:ruby_version]
104
- line << ",rubygems:#{version[:rubygems_version]}" if version[:rubygems_version]
105
-
106
- line
107
77
  end
108
78
  end
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CompactIndex
2
4
  Dependency = Struct.new(:gem, :version, :platform, :checksum) do
3
5
  def version_and_platform
4
- if platform.nil? || platform == 'ruby'
6
+ if platform.nil? || platform == "ruby"
5
7
  version.dup
6
8
  else
7
9
  "#{version}-#{platform}"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "date"
2
4
 
3
5
  # Ruby 1.8.7 makes Time#to_datetime private, but we need it
@@ -5,4 +7,4 @@ unless Time.public_instance_methods.include? :to_datetime
5
7
  class Time
6
8
  public :to_datetime
7
9
  end
8
- end
10
+ end
@@ -1,3 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CompactIndex
2
- Gem = Struct.new(:name, :versions)
4
+ Gem = Struct.new(:name, :versions) do
5
+ def <=>(other)
6
+ name <=> other.name
7
+ end
8
+ end
3
9
  end
@@ -1,12 +1,53 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CompactIndex
4
+ # rubocop:disable Metrics/BlockLength
2
5
  GemVersion = Struct.new(:number, :platform, :checksum, :info_checksum,
3
- :dependencies, :ruby_version, :rubygems_version) do
6
+ :dependencies, :ruby_version, :rubygems_version) do
4
7
  def number_and_platform
5
- if platform.nil? || platform == 'ruby'
8
+ if platform.nil? || platform == "ruby"
6
9
  number.dup
7
10
  else
8
11
  "#{number}-#{platform}"
9
12
  end
10
13
  end
14
+
15
+ def <=>(other)
16
+ number_comp = number <=> other.number
17
+
18
+ if number_comp.zero?
19
+ [number, platform].compact <=> [other.number, other.platform].compact
20
+ else
21
+ number_comp
22
+ end
23
+ end
24
+
25
+ def to_line
26
+ line = number_and_platform.dup << " " << deps_line << "|checksum:#{checksum}"
27
+ line << ",ruby:#{ruby_version_line}" if ruby_version && ruby_version != ">= 0"
28
+ line << ",rubygems:#{rubygems_version_line}" if rubygems_version && rubygems_version != ">= 0"
29
+ line
30
+ end
31
+
32
+ private
33
+
34
+ def ruby_version_line
35
+ join_multiple(ruby_version)
36
+ end
37
+
38
+ def rubygems_version_line
39
+ join_multiple(rubygems_version)
40
+ end
41
+
42
+ def deps_line
43
+ return "" if dependencies.nil?
44
+ dependencies.map do |d|
45
+ [d[:gem], join_multiple(d.version_and_platform)].join(":")
46
+ end.join(",")
47
+ end
48
+
49
+ def join_multiple(requirements)
50
+ requirements.split(", ").sort.join("&")
51
+ end
11
52
  end
12
53
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CompactIndex
2
- VERSION = "0.9.4"
4
+ VERSION = "0.13.0".freeze
3
5
  end
@@ -1,116 +1,68 @@
1
- require 'time'
2
- require 'date'
3
- require 'digest'
4
- require 'compact_index'
1
+ # frozen_string_literal: true
5
2
 
6
- class CompactIndex::VersionsFile
7
- def initialize(file = nil)
8
- @path = file || "/versions.list"
9
- end
3
+ require "time"
4
+ require "date"
5
+ require "digest"
10
6
 
11
- def contents(gems = nil, args = {})
12
- if args[:calculate_checksums]
13
- gems = calculate_checksums(gems)
7
+ module CompactIndex
8
+ class VersionsFile
9
+ def initialize(file = nil)
10
+ @path = file || "/versions.list"
14
11
  end
15
12
 
16
- out = File.read(@path)
17
- out << parse_gems(gems) if gems
18
- out
19
- end
20
-
21
- def updated_at
22
- created_at_header(@path) || Time.at(0).to_datetime
23
- end
24
-
25
- def update_with(gems)
26
- if File.exists?(@path) && !File.zero?(@path)
27
- update(gems)
28
- else
29
- create(gems)
30
- end
31
- end
13
+ def contents(gems = nil, args = {})
14
+ gems = calculate_info_checksums(gems) if args.delete(:calculate_info_checksums) { false }
32
15
 
16
+ raise ArgumentError, "Unknown options: #{args.keys.join(", ")}" unless args.empty?
33
17
 
34
- private
35
-
36
-
37
- def create(gems)
38
- content = "created_at: #{Time.now.iso8601}"
39
- content << "\n---\n"
40
- content << parse_gems_for_create(gems)
41
-
42
- File.open(@path, 'w') do |io|
43
- io.write content
18
+ File.read(@path).tap do |out|
19
+ out << gem_lines(gems) if gems
20
+ end
44
21
  end
45
- end
46
22
 
47
- def update(gems)
48
- File.open(@path, 'a') do |io|
49
- io.write parse_gems(gems)
23
+ def updated_at
24
+ created_at_header(@path) || Time.at(0).to_datetime
50
25
  end
51
- end
52
26
 
53
- def parse_gems_for_create(gems)
54
- # Join all versions for each gem in one hash
55
- gems_hash = {}
56
- gems.each do |entry|
57
- gems_hash[entry[:name]] ||= []
58
- gems_hash[entry[:name]] += entry[:versions]
59
- end
27
+ def create(gems)
28
+ gems.sort!
60
29
 
61
- # Transform hash in a list of line informations to be printed
62
- gems = gems_hash.map do |gem, versions|
63
- { :name => gem, :versions => versions, :checksum => versions.first[:checksum] }
64
- end
65
-
66
- # Sort gems by name and versions by number
67
- gems.sort! { |a,b| a[:name] <=> b[:name] }
68
- gems.each do |entry|
69
- entry[:versions].sort! do |a,b|
70
- Gem::Version.create(a[:number]) <=> Gem::Version.create(b[:number])
30
+ File.open(@path, "w") do |io|
31
+ io.write "created_at: #{Time.now.iso8601}\n---\n"
32
+ io.write gem_lines(gems)
71
33
  end
72
34
  end
73
35
 
74
- gem_lines(gems)
75
- end
76
-
77
- def parse_gems(gems)
78
- gem_lines = gems.map do |entry|
79
- {
80
- :name => entry[:name],
81
- :versions => entry[:versions],
82
- :checksum => entry[:versions].first[:checksum]
83
- }
84
- end
85
- gem_lines(gem_lines)
86
- end
36
+ private
87
37
 
88
- def gem_lines(gems)
89
- gems.reduce("") do |concat, entry|
90
- versions = entry[:versions]
91
- concat << "#{entry[:name]} #{versions.map(&:number_and_platform).join(',')} #{entry[:checksum]}\n"
38
+ def gem_lines(gems)
39
+ gems.reduce("".dup) do |lines, gem|
40
+ version_numbers = gem.versions.map(&:number_and_platform).join(",")
41
+ lines << gem.name <<
42
+ " ".freeze << version_numbers <<
43
+ " #{gem.versions.last.info_checksum}\n"
44
+ end
92
45
  end
93
- end
94
46
 
95
- def calculate_checksums(gems)
96
- gems.each do |gem|
97
- info_checksum = Digest::MD5.hexdigest(CompactIndex.info(gem[:versions]))
98
- gem[:versions].first[:checksum] = info_checksum
47
+ def calculate_info_checksums(gems)
48
+ gems.each do |gem|
49
+ info_checksum = Digest::MD5.hexdigest(CompactIndex.info(gem[:versions]))
50
+ gem[:versions].last[:info_checksum] = info_checksum
51
+ end
99
52
  end
100
- end
101
53
 
102
- def created_at_header(path)
103
- return unless File.exists? path
54
+ def created_at_header(path)
55
+ return unless File.exist? path
104
56
 
105
- File.open(path) do |file|
106
- file.each_line do |line|
107
- line.match(/created_at: (.*)\n|---\n/) do |match|
108
- return match[1] && DateTime.parse(match[1])
57
+ File.open(path) do |file|
58
+ file.each_line do |line|
59
+ line.match(/created_at: (.*)\n|---\n/) do |match|
60
+ return match[1] && DateTime.parse(match[1])
61
+ end
109
62
  end
110
63
  end
111
- end
112
64
 
113
- nil
65
+ nil
66
+ end
114
67
  end
115
-
116
68
  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.9.4
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
- - fotanus@gmail.com
7
+ - Felipe Tanus
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-05 00:00:00.000000000 Z
11
+ date: 2020-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '10.0'
19
+ version: '13.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '10.0'
26
+ version: '13.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -40,7 +40,7 @@ dependencies:
40
40
  version: '3'
41
41
  description:
42
42
  email:
43
- - Felipe Tanus
43
+ - fotanus@gmail.com
44
44
  executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
@@ -55,6 +55,7 @@ files:
55
55
  - CHANGELOG.md
56
56
  - CODE_OF_CONDUCT.md
57
57
  - Gemfile
58
+ - Gemfile.lock
58
59
  - LICENSE.txt
59
60
  - README.md
60
61
  - Rakefile
@@ -75,7 +76,7 @@ files:
75
76
  - lib/compact_index/gem_version.rb
76
77
  - lib/compact_index/version.rb
77
78
  - lib/compact_index/versions_file.rb
78
- homepage: https://github.com/bundler/compact_index
79
+ homepage: https://github.com/rubygems/compact_index
79
80
  licenses:
80
81
  - MIT
81
82
  metadata: {}
@@ -94,8 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
95
  - !ruby/object:Gem::Version
95
96
  version: '0'
96
97
  requirements: []
97
- rubyforge_project:
98
- rubygems_version: 2.4.6
98
+ rubygems_version: 3.0.1
99
99
  signing_key:
100
100
  specification_version: 4
101
101
  summary: Backend for compact index