compact_index 0.9.0 → 0.9.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: d64d44d1fea23ce0a76b7845acc0014b8ca8aec7
4
- data.tar.gz: 51b9ae7960a546363e9d78327467f7a8b482ab68
3
+ metadata.gz: 1910b8bcbe07ae4b1503386a945c527e9dae0c82
4
+ data.tar.gz: eaccc11cf9d9d8e329b66278c1b6a4913225f882
5
5
  SHA512:
6
- metadata.gz: 7aee9ae1d0b33076d8e6109cef53eee7c2e4e805007114f446b50736c9cfd4f3877fd2dbd27dcb1096294b771a90386ea2a6d20a3a39f35a18d0d267d2cd01ae
7
- data.tar.gz: 434971c492a216938303c67a16cdb399a49aed8232065c6f93640830bf2e86e842debca4a3dffc51cf4f5431fb9b5ace7104c49db004ca67d0bff597e5ccf4c9
6
+ metadata.gz: f4c4d5386521b6e29028a09165f16af8cb5da09cd19fed220d003fdfc30e0b86ffeafd602e612830184d3a474090c0ac65d4b03a8f5f403a9d1a74a870e56af2
7
+ data.tar.gz: 222bf16b5c83f0927cd5770d7e63497ef410b3db62c280c10d5badf546e8e475f6437f5f87547ec161e6811dca8f3312cc434a56bd287650a01e13753855a1a3
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.9.1 (August 19, 2015)
2
+
3
+ Features:
4
+
5
+ - Add an option to CompactIndex.versions to calculate info_checksums on the fly
6
+
1
7
  ## 0.9.0 (August 17, 2015)
2
8
 
3
9
  Features:
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # CompactIndex
4
4
 
5
- Backend for bundler compact index. Used by rubygems.org and bundler-api
5
+ This gem implements the response logic for the compact index format and to manage the versions file. The compact index format has three endpoints: `/names`, `/versions` and `/info/gem_name`. The versions file is a file which hold the versions in a cache-friendly way. You can see the body response formats on [this blog post](http://andre.arko.net/2014/03/28/the-new-rubygems-index-format/) from @indirect.
6
6
 
7
7
  ## Installation
8
8
 
@@ -16,11 +16,101 @@ And then execute:
16
16
 
17
17
  $ bundle
18
18
 
19
- Or install it yourself as:
19
+ ## Usage
20
20
 
21
- $ gem install compact_index
21
+ ### `/names`
22
+
23
+ To render the body for this call, all you have to do is generate a list of gems available in alfabetical order and use call `CompactIndex.names`.
24
+
25
+ ```ruby
26
+ gem 'compact_index'
27
+ CompactIndex.names(%W(a_test b_test c_test))
28
+ ```
29
+
30
+ ### `/versions`
31
+
32
+ The body of this endpoint can be rendered calling the `CompactIndex.versions` method. It receives two paremeters: a `CompactIndex::VersionsFile` object and a set of extra gems that aren't in the file yet. The gems lists should be ordered consistently by the user.
33
+
34
+ ```ruby
35
+ gem 'compact_index'
36
+ # Create the object
37
+ versions_file = CompactIndex::VersionsFile.new("/path/to/versions/file")
38
+
39
+ # Get last updated date. This is used to discover what gems aren't in the file yet
40
+ from_date = @versions_file.updated_at
41
+
42
+ # Query the extra gems using the from date. Format should be as follows
43
+ extra_gems = [
44
+ {
45
+ name: "gem1",
46
+ versions: [
47
+ {
48
+ number: "0.9.8"
49
+ platform: "ruby"
50
+ checksum: "abc123" #sha256 checksum available on rubygems.org
51
+ },
52
+ {
53
+ number: "0.9.9"
54
+ platform: "java"
55
+ checksum: "abc123"
56
+ }
57
+ ]
58
+ },
59
+ {
60
+ name: "gem2",
61
+ versions: [
62
+ {
63
+ number: "0.9.8"
64
+ platform: "ruby"
65
+ checksum: "abc123" #sha256 checksum available on rubygems.org
66
+ },
67
+ {
68
+ number: "0.9.9"
69
+ platform: "java"
70
+ checksum: "abc123"
71
+ }
72
+ ]
73
+ }
74
+ ]
22
75
 
23
- ## Usage
24
76
 
25
- TODO: Write usage instructions here
77
+ # Render the body for the versions response
78
+ CompactIndex.versions(@versions_file, extra_gems)
79
+ ```
80
+
81
+ ### `/info/gem_name`
82
+
83
+ Much like `/versions`, the `/info/gem_name` expects a pre-defined structure to render the text on the screen. The lists also should be ordered by the user. This is the expected format:
84
+
85
+ ```ruby
86
+ gem 'compact_index'
87
+
88
+ # Expected versions format
89
+ versions = [
90
+ {
91
+ number: '1.0.1',
92
+ checksum: "abc123",
93
+ dependencies: [
94
+ {
95
+ gem: 'foo',
96
+ version: '=1.0.1',
97
+ checksum: 'abc123'
98
+ }
99
+ ]
100
+ }
101
+ ]
102
+ CompactIndex.info(versions)
103
+ ```
104
+
105
+ ### Updating the versions file
26
106
 
107
+ The versions file creation and update are different. When created, all versions are at the side of the gem name, which appears only on one line. When updated, the file appends the new information on the end of the file, to avoid file changes.
108
+
109
+ ```ruby
110
+ gem 'compact_index'
111
+
112
+ versions_file = CompactIndex::VersionsFile.new(file_path)
113
+ last_update = versions_file.updated_at
114
+ gems = ... # Query your database, same format from `/versions` expected
115
+ versions_file.update_with(gems)
116
+ ```
@@ -1,3 +1,3 @@
1
1
  module CompactIndex
2
- VERSION = "0.9.0"
2
+ VERSION = "0.9.1"
3
3
  end
@@ -5,7 +5,11 @@ class CompactIndex::VersionsFile
5
5
  @path = file || "/versions.list"
6
6
  end
7
7
 
8
- def contents(gems=nil)
8
+ def contents(gems=nil, args = {})
9
+ if args[:calculate_checksums]
10
+ gems = calculate_checksums(gems)
11
+ end
12
+
9
13
  out = File.read(@path)
10
14
  out << parse_gems(gems) if gems
11
15
  out
@@ -90,9 +94,16 @@ class CompactIndex::VersionsFile
90
94
 
91
95
  def number_and_platform(number, platform)
92
96
  if platform.nil? || platform == 'ruby'
93
- number
97
+ number.dup
94
98
  else
95
99
  "#{number}-#{platform}"
96
100
  end
97
101
  end
102
+
103
+ def calculate_checksums(gems)
104
+ gems.each do |gem|
105
+ info_checksum = Digest::MD5.hexdigest(CompactIndex.info(gem[:versions]))
106
+ gem[:versions].first[:checksum] = info_checksum
107
+ end
108
+ end
98
109
  end
data/lib/compact_index.rb CHANGED
@@ -6,8 +6,8 @@ module CompactIndex
6
6
  "---\n" << gem_names.join("\n") << "\n"
7
7
  end
8
8
 
9
- def self.versions(versions_file, gems)
10
- versions_file.contents(gems)
9
+ def self.versions(versions_file, gems, args)
10
+ versions_file.contents(gems, args)
11
11
  end
12
12
 
13
13
  def self.info(params)
@@ -46,7 +46,7 @@ module CompactIndex
46
46
 
47
47
  def self.number_and_platform(number, platform)
48
48
  if platform.nil? || platform == 'ruby'
49
- number
49
+ number.dup
50
50
  else
51
51
  "#{number}-#{platform}"
52
52
  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.0
4
+ version: 0.9.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-08-18 00:00:00.000000000 Z
11
+ date: 2015-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake