rubygems-appender 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7160ffa9a68a98b520ff070d36adb276c2284bfa5e7c8256210199f99490b852
4
+ data.tar.gz: 1e5db3ded89901fadd10ce1277d9abb262163f9df0b51aed38f02a06b6c7ef61
5
+ SHA512:
6
+ metadata.gz: 60ea92029a16889dcf58d945c3cd2ac68cfdd3e81764952410a38dc1cdc5890daa0bbc53038b47a307610544f58439cc31025378352278c750dfa0dee2be12e9
7
+ data.tar.gz: 6fab7608d89dbd4e2310759efc05d75408e972d9f26503b0727f192cb4c981d238653296ea16868375264a5a4adf4ebac97a292cb2adee57a7abf6ac39d1209c
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2018 David Kuo (me@davy.tw)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # RubyGems Appender
2
+
3
+ This plugin can let you append gems into indexes without pulling all gems.
4
+
5
+ ## Usage
6
+
7
+ Put your gems into `gems` inside indexes directory structure.
8
+
9
+ And remember to put last indexes (and `quick`) into the directory.
10
+
11
+ ```
12
+ > indexer = Gem::Indexer.new('path/to/indexes_directory')
13
+ > indexer.appender do |c|
14
+ > c.add('gem/some_awesome_gem-2.0.0.gem')
15
+ > c.add('gem/some_awesome_gem-2.1.0.gem')
16
+ > end
17
+ Generating Marshal quick index gemspecs for 2 gems
18
+
19
+ Complete
20
+ Generated Marshal quick index gemspecs: 0.000s
21
+ Generating specs index
22
+ Generated specs index: 0.000s
23
+ Generating latest specs index
24
+ Generated latest specs index: 0.000s
25
+ Generating prerelease specs index
26
+ Generated prerelease specs index: 0.014s
27
+ Compressing indices
28
+ Compressed indices: 0.001s
29
+ ```
30
+
31
+ :tada:
32
+
33
+ ## License
34
+
35
+ MIT License.
@@ -0,0 +1,6 @@
1
+ require 'rubygems/indexer'
2
+ require 'rubygems-appender/appender'
3
+
4
+ class Gem::Indexer
5
+ prepend RubyGemsAppender::Appender
6
+ end
@@ -0,0 +1,116 @@
1
+ require 'rubygems-appender/container'
2
+
3
+ module RubyGemsAppender
4
+ module Appender
5
+ def current_spec_indexes
6
+ Marshal.load(Gem.read_binary(@dest_specs_index))
7
+ end
8
+ def current_prerelease_spec_indexes
9
+ Marshal.load(Gem.read_binary(@dest_prerelease_specs_index))
10
+ end
11
+ def current_latest_spec_indexes
12
+ Marshal.load(Gem.read_binary(@dest_latest_specs_index))
13
+ end
14
+
15
+ def appender(&block)
16
+ container = Container.new self
17
+ yield container
18
+ container.pull_gemspecs!
19
+
20
+ make_temp_directories
21
+
22
+ files = Gem.time 'Build Marshal gemspecs' do
23
+ build_marshal_gemspecs(container.specs)
24
+ end
25
+
26
+ if files.empty?
27
+ say 'Gems not found'
28
+ return
29
+ end
30
+
31
+ prerelease, released = container.specs.partition { |s| s.version.prerelease? }
32
+ released_indexes = Gem.time 'Update released indexes' do
33
+ released_indexes = current_spec_indexes.tap do |specs|
34
+ specs.push(*released.map do |spec|
35
+ build_spec_index spec
36
+ end)
37
+ end.uniq.sort
38
+ write_spec_indexes released_indexes, @specs_index
39
+ released_indexes
40
+ end
41
+ Gem.time 'Update pre-release indexes' do
42
+ prerelease_indexes = current_prerelease_spec_indexes.tap do |specs|
43
+ specs.push(*prerelease.map do |spec|
44
+ build_spec_index spec
45
+ end)
46
+ end.uniq.sort - released_indexes
47
+ write_spec_indexes prerelease_indexes, @prerelease_specs_index
48
+ end
49
+ Gem.time 'Update latest indexes' do
50
+ latest_indexes = Hash.new { |hsh, k| hsh[k] = [] } .tap do |map|
51
+ current_latest_spec_indexes.each do |index|
52
+ name, _ = index
53
+ map[name] << index
54
+ end
55
+
56
+ released.map do |spec|
57
+ index = build_spec_index spec
58
+ name, _ = index
59
+ map[name] << index
60
+ end
61
+ end.values.map do |indexes|
62
+ indexes.sort! { |(_, l, _), (_, r, _)| l <=> r }.last
63
+ end
64
+ write_spec_indexes latest_indexes, @latest_specs_index
65
+ end
66
+
67
+ compress_indices
68
+
69
+ files += [
70
+ @specs_index,
71
+ "#{@specs_index}.gz",
72
+ @latest_specs_index,
73
+ "#{@latest_specs_index}.gz",
74
+ @prerelease_specs_index,
75
+ "#{@prerelease_specs_index}.gz",
76
+ ]
77
+
78
+ install_appended_indices(files)
79
+ ensure
80
+ FileUtils.rm_rf @directory
81
+ end
82
+
83
+ protected
84
+
85
+ def build_spec_index(spec)
86
+ platform = spec.original_platform
87
+ platform = Gem::Platform::RUBY if platform.nil? or platform.empty?
88
+
89
+ [spec.name, spec.version, platform]
90
+ end
91
+
92
+ def write_spec_indexes(indexes, filename)
93
+ File.open filename, 'wb' do |io|
94
+ Marshal.dump(compact_specs(indexes), io)
95
+ end
96
+ end
97
+
98
+ def install_appended_indices(files)
99
+ verbose = Gem.configuration.really_verbose
100
+
101
+ FileUtils.mkdir_p(File.join(@dest_directory, @quick_marshal_dir_base))
102
+
103
+ files.each do |tmpfile|
104
+ file = tmpfile.sub(/^#{Regexp.escape @directory}\/?/, '') # HACK?
105
+
106
+ src_name = File.join @directory, file
107
+ dst_name = File.join @dest_directory, file
108
+
109
+ FileUtils.rm_rf(dst_name, verbose: verbose)
110
+ FileUtils.mv(src_name, dst_name,
111
+ verbose: verbose,
112
+ force: true)
113
+ end
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,32 @@
1
+ module RubyGemsAppender
2
+ class Container
3
+ attr_reader :specs
4
+
5
+ def initialize(indexer)
6
+ @specs = []
7
+ @gems = []
8
+ @indexer = indexer
9
+ end
10
+
11
+ def add(spec_or_gem)
12
+ if spec_or_gem.is_a? String
13
+ add_gem(spec_or_gem)
14
+ else
15
+ add_spec(spec_or_gem)
16
+ end
17
+ end
18
+
19
+ def add_spec(spec)
20
+ @specs << spec
21
+ end
22
+
23
+ def add_gem(path)
24
+ @gems << path
25
+ end
26
+
27
+ def pull_gemspecs!
28
+ @specs.push(*@indexer.map_gems_to_specs(@gems))
29
+ @gems.clear
30
+ end
31
+ end
32
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubygems-appender
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - David Kuo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-10-16 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Appends new gems to generated index without old gems exists.
14
+ email: me@davy.tw
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - LICENSE
20
+ - README.md
21
+ - lib/rubygems-appender.rb
22
+ - lib/rubygems-appender/appender.rb
23
+ - lib/rubygems-appender/container.rb
24
+ homepage: https://github.com/david50407/rubygems-appender
25
+ licenses:
26
+ - MIT
27
+ metadata: {}
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 2.7.3
45
+ signing_key:
46
+ specification_version: 4
47
+ summary: Appends gems into RubyGems formatted index.
48
+ test_files: []