gemirro 0.12.0 → 0.13.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of gemirro might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8982c03b3986ec30f9cb52186836ff37b677a369
4
- data.tar.gz: 4983fc83b1bf255c6b74da5a66482ac868ae66c2
3
+ metadata.gz: 836bd37bcd65885bdd10b4faaa752084fb15aa82
4
+ data.tar.gz: 672147cad4d0d681e103a9c791fc8cd807a14365
5
5
  SHA512:
6
- metadata.gz: 379c27532e2525d86ee0590b9b42697672a1e44c517574d6ded98bfc52fd7699192df09cab8158c19a8edacd325a430e946f980ddc18d483b72352ebd4840252
7
- data.tar.gz: 0ff72c9c524b607df1a98dd2f1662522ef8c5d2fa743a0247241ba7a65b30c3f1049915345157ad05a2ede29ff6d6d9bdad33ab29f74a8703b2e637586293fb4
6
+ metadata.gz: c416be87d6a284fcf752b39cfac3f203e291a0dc7022294a090a844acb5cdb1da829b18878f2decd553d545a5cba11c0defaa56f8062ba166ef18a6b554af229
7
+ data.tar.gz: 96a558e31033dee1f7f58f84edea8c5ffbab24ee2ad0394346624abb92eb8510b4406ad294128893ba8ffc564ad01398d45741ca4de1ddcc26b57e21ca616237
data/MANIFEST CHANGED
@@ -13,6 +13,7 @@ lib/gemirro/cache.rb
13
13
  lib/gemirro/cli.rb
14
14
  lib/gemirro/cli/index.rb
15
15
  lib/gemirro/cli/init.rb
16
+ lib/gemirro/cli/list.rb
16
17
  lib/gemirro/cli/server.rb
17
18
  lib/gemirro/cli/update.rb
18
19
  lib/gemirro/configuration.rb
@@ -26,11 +27,13 @@ lib/gemirro/mirror_directory.rb
26
27
  lib/gemirro/mirror_file.rb
27
28
  lib/gemirro/server.rb
28
29
  lib/gemirro/source.rb
30
+ lib/gemirro/utils.rb
29
31
  lib/gemirro/version.rb
30
32
  lib/gemirro/versions_fetcher.rb
31
33
  lib/gemirro/versions_file.rb
32
34
  spec/fixtures/gems/gemirro-0.0.1.gem
33
35
  spec/fixtures/quick/gemirro-0.0.1.gemspec.rz
36
+ spec/gemirro/cache_spec.rb
34
37
  spec/gemirro/cli_spec.rb
35
38
  spec/gemirro/configuration_spec.rb
36
39
  spec/gemirro/gem_spec.rb
@@ -64,4 +67,4 @@ template/public/gems/.gitkeep
64
67
  views/gem.erb
65
68
  views/index.erb
66
69
  views/layout.erb
67
- views/not_found.erb
70
+ views/not_found.erb
data/gemirro.gemspec CHANGED
@@ -30,6 +30,6 @@ Gem::Specification.new do |s|
30
30
  s.add_development_dependency 'rack-test', '~>0.6'
31
31
  s.add_development_dependency 'rspec', '~>3.2'
32
32
  s.add_development_dependency 'simplecov', '~>0.9'
33
- s.add_development_dependency 'rubocop', '~>0.30'
33
+ s.add_development_dependency 'rubocop', '~>0.35'
34
34
  s.add_development_dependency 'fakefs', '~>0.6.7'
35
35
  end
data/lib/gemirro.rb CHANGED
@@ -21,6 +21,7 @@ end
21
21
  require 'gemirro/version'
22
22
  require 'gemirro/configuration'
23
23
  require 'gemirro/cache'
24
+ require 'gemirro/utils'
24
25
  require 'gemirro/gem'
25
26
  require 'gemirro/gem_version'
26
27
  require 'gemirro/gem_version_collection'
@@ -34,7 +35,8 @@ require 'gemirro/versions_fetcher'
34
35
  require 'gemirro/gems_fetcher'
35
36
 
36
37
  require 'gemirro/cli'
37
- require 'gemirro/cli/init'
38
- require 'gemirro/cli/update'
39
38
  require 'gemirro/cli/index'
39
+ require 'gemirro/cli/init'
40
+ require 'gemirro/cli/list'
40
41
  require 'gemirro/cli/server'
42
+ require 'gemirro/cli/update'
data/lib/gemirro/cli.rb CHANGED
@@ -30,7 +30,8 @@ module Gemirro
30
30
  def self.load_configuration(config_file)
31
31
  config_file ||= Configuration.default_configuration_file
32
32
  config_file = File.expand_path(config_file, Dir.pwd)
33
- config_file += '/config.rb' unless config_file.end_with?('config.rb')
33
+ config_file += '/config.rb' unless config_file.end_with?('.rb') ||
34
+ !File.directory?(config_file)
34
35
 
35
36
  unless File.file?(config_file)
36
37
  abort "The configuration file #{config_file} does not exist"
@@ -3,14 +3,24 @@ Gemirro::CLI.options.command 'init' do
3
3
  banner 'Usage: gemirro init [DIRECTORY] [OPTIONS]'
4
4
  description 'Sets up a new mirror'
5
5
  separator "\nOptions:\n"
6
+ on :force, 'Force overwrite'
6
7
 
7
- run do |_opts, args|
8
+ run do |opts, args|
8
9
  directory = File.expand_path(args[0] || Dir.pwd)
9
10
  template = Gemirro::Configuration.template_directory
10
11
 
11
12
  Dir.mkdir(directory) unless File.directory?(directory)
12
13
 
13
- FileUtils.cp_r(File.join(template, '.'), directory)
14
+ if opts[:force]
15
+ FileUtils.cp_r(File.join(template, '.'), directory)
16
+ else
17
+ Dir.glob("#{template}/**/*", File::FNM_DOTMATCH).each do |file|
18
+ next if ['.', '..'].include?(File.basename(file))
19
+ dest = File.join(directory, file.gsub(/^#{template}/, ''))
20
+ next if File.exist?(dest)
21
+ FileUtils.cp_r(file, dest)
22
+ end
23
+ end
14
24
 
15
25
  puts "Initialized empty mirror in #{directory}"
16
26
  end
@@ -0,0 +1,23 @@
1
+ # -*- coding: utf-8 -*-
2
+ Gemirro::CLI.options.command 'list' do
3
+ banner 'Usage: gemirro list [OPTIONS]'
4
+ description 'List available gems.'
5
+ separator "\nOptions:\n"
6
+
7
+ on :c=, :config=, 'Path to the configuration file'
8
+
9
+ run do |opts, _args|
10
+ Gemirro::CLI.load_configuration(opts[:c])
11
+ config = Gemirro.configuration
12
+
13
+ unless File.directory?(config.destination)
14
+ config.logger.error("The directory #{config.destination} does not exist")
15
+ abort
16
+ end
17
+
18
+ gems = Gemirro::Utils.gems_collection.group_by(&:name).sort
19
+ gems.each do |name, versions|
20
+ puts "#{name}: (#{versions.map(&:number).join(', ')})"
21
+ end
22
+ end
23
+ end
@@ -110,7 +110,7 @@ Gemirro::CLI.options.command 'server' do
110
110
  end
111
111
 
112
112
  def running?(process_id)
113
- Process.getpgid(process_id) != -1
113
+ Process.getpgid(process_id.to_i) != -1
114
114
  rescue Errno::ESRCH
115
115
  false
116
116
  end
data/lib/gemirro/gem.rb CHANGED
@@ -15,6 +15,7 @@ module Gemirro
15
15
  class Gem
16
16
  attr_reader :name, :requirement, :platform, :version
17
17
  attr_accessor :gemspec
18
+ ONLY_LATEST = [:latest, :newest]
18
19
 
19
20
  ##
20
21
  # Returns a `Gem::Version` instance based on the specified requirement.
@@ -60,6 +61,20 @@ module Gemirro
60
61
  version && !version.segments.reject { |s| s == 0 }.empty?
61
62
  end
62
63
 
64
+ ##
65
+ # Define if version exists
66
+ #
67
+ # @return [TrueClass|FalseClass]
68
+ #
69
+ def only_latest?
70
+ @requirement.is_a?(Symbol) && ONLY_LATEST.include?(@requirement)
71
+ end
72
+
73
+ ##
74
+ # Is gemspec
75
+ #
76
+ # @return [TrueClass|FalseClass]
77
+ #
63
78
  def gemspec?
64
79
  @gemspec == true
65
80
  end
@@ -29,11 +29,11 @@ module Gemirro
29
29
  versions_for(gem).each do |version|
30
30
  if gem.gemspec?
31
31
  gemfile = fetch_gemspec(gem, version)
32
- configuration.mirror_gemspecs_directory
32
+ Utils.configuration.mirror_gemspecs_directory
33
33
  .add_file(gem.gemspec_filename(version), gemfile) if gemfile
34
34
  else
35
35
  gemfile = fetch_gem(gem, version)
36
- configuration.mirror_gems_directory
36
+ Utils.configuration.mirror_gems_directory
37
37
  .add_file(gem.filename(version), gemfile) if gemfile
38
38
  end
39
39
  end
@@ -49,6 +49,8 @@ module Gemirro
49
49
  #
50
50
  def versions_for(gem)
51
51
  available = @versions_file.versions_for(gem.name)
52
+ return [available.last] if gem.only_latest?
53
+
52
54
  versions = available.select do |v|
53
55
  gem.requirement.satisfied_by?(v)
54
56
  end
@@ -67,14 +69,18 @@ module Gemirro
67
69
  #
68
70
  def fetch_gemspec(gem, version)
69
71
  filename = gem.gemspec_filename(version)
70
- satisfied = gem.requirement.satisfied_by?(version)
72
+ satisfied = if gem.only_latest?
73
+ true
74
+ else
75
+ gem.requirement.satisfied_by?(version)
76
+ end
71
77
 
72
78
  if gemspec_exists?(filename) || !satisfied
73
- logger.debug("Skipping #{filename}")
79
+ Utils.logger.debug("Skipping #{filename}")
74
80
  return
75
81
  end
76
82
 
77
- logger.info("Fetching #{filename}")
83
+ Utils.logger.info("Fetching #{filename}")
78
84
  fetch_from_source(gem, version, true)
79
85
  end
80
86
 
@@ -87,16 +93,20 @@ module Gemirro
87
93
  #
88
94
  def fetch_gem(gem, version)
89
95
  filename = gem.filename(version)
90
- satisfied = gem.requirement.satisfied_by?(version)
96
+ satisfied = if gem.only_latest?
97
+ true
98
+ else
99
+ gem.requirement.satisfied_by?(version)
100
+ end
91
101
  name = gem.name
92
102
 
93
103
  if gem_exists?(filename) || ignore_gem?(name, version) || !satisfied
94
- logger.debug("Skipping #{filename}")
104
+ Utils.logger.debug("Skipping #{filename}")
95
105
  return
96
106
  end
97
107
 
98
- configuration.ignore_gem(gem.name, version)
99
- logger.info("Fetching #{filename}")
108
+ Utils.configuration.ignore_gem(gem.name, version)
109
+ Utils.logger.info("Fetching #{filename}")
100
110
 
101
111
  fetch_from_source(gem, version)
102
112
  end
@@ -115,30 +125,15 @@ module Gemirro
115
125
  data = @source.fetch_gemspec(gem.name, version) if gemspec
116
126
  rescue => e
117
127
  filename = gem.filename(version)
118
- logger.error("Failed to retrieve #{filename}: #{e.message}")
119
- logger.debug("Adding #{filename} to the list of ignored Gems")
128
+ Utils.logger.error("Failed to retrieve #{filename}: #{e.message}")
129
+ Utils.logger.debug("Adding #{filename} to the list of ignored Gems")
120
130
 
121
- configuration.ignore_gem(gem.name, version)
131
+ Utils.configuration.ignore_gem(gem.name, version)
122
132
  end
123
133
 
124
134
  data
125
135
  end
126
136
 
127
- ##
128
- # @see Gemirro::Configuration#logger
129
- # @return [Logger]
130
- #
131
- def logger
132
- configuration.logger
133
- end
134
-
135
- ##
136
- # @see Gemirro.configuration
137
- #
138
- def configuration
139
- Gemirro.configuration
140
- end
141
-
142
137
  ##
143
138
  # Checks if a given Gem has already been downloaded.
144
139
  #
@@ -146,7 +141,7 @@ module Gemirro
146
141
  # @return [TrueClass|FalseClass]
147
142
  #
148
143
  def gem_exists?(filename)
149
- configuration.mirror_gems_directory.file_exists?(filename)
144
+ Utils.configuration.mirror_gems_directory.file_exists?(filename)
150
145
  end
151
146
 
152
147
  ##
@@ -156,14 +151,14 @@ module Gemirro
156
151
  # @return [TrueClass|FalseClass]
157
152
  #
158
153
  def gemspec_exists?(filename)
159
- configuration.mirror_gemspecs_directory.file_exists?(filename)
154
+ Utils.configuration.mirror_gemspecs_directory.file_exists?(filename)
160
155
  end
161
156
 
162
157
  ##
163
158
  # @see Gemirro::Configuration#ignore_gem?
164
159
  #
165
160
  def ignore_gem?(*args)
166
- configuration.ignore_gem?(*args)
161
+ Utils.configuration.ignore_gem?(*args)
167
162
  end
168
163
  end
169
164
  end
@@ -25,7 +25,6 @@ module Gemirro
25
25
  :dest_directory,
26
26
  :only_origin,
27
27
  :updated_gems)
28
- attr_reader :cache
29
28
 
30
29
  ##
31
30
  # Create an indexer that will index the gems in +directory+.
@@ -86,7 +85,7 @@ module Gemirro
86
85
  # @return [Array]
87
86
  #
88
87
  def install_indicies
89
- logger
88
+ Utils.logger
90
89
  .debug("Downloading index into production dir #{@dest_directory}")
91
90
 
92
91
  files = @files
@@ -129,7 +128,7 @@ module Gemirro
129
128
  #
130
129
  def download_from_source(file)
131
130
  source_host = Gemirro.configuration.source.host
132
- logger.info("Download from source: #{file}")
131
+ Utils.logger.info("Download from source: #{file}")
133
132
  resp = Http.get("#{source_host}/#{File.basename(file)}")
134
133
  return unless resp.code == 200
135
134
  resp.body
@@ -161,11 +160,11 @@ module Gemirro
161
160
  def map_gems_to_specs(gems)
162
161
  gems.map.with_index do |gemfile, index|
163
162
  # rubocop:disable Metrics/LineLength
164
- logger.info("[#{index + 1}/#{gems.size}]: Processing #{gemfile.split('/')[-1]}")
163
+ Utils.logger.info("[#{index + 1}/#{gems.size}]: Processing #{gemfile.split('/')[-1]}")
165
164
  # rubocop:enable Metrics/LineLength
166
165
 
167
166
  if File.size(gemfile) == 0
168
- logger.warn("Skipping zero-length gem: #{gemfile}")
167
+ Utils.logger.warn("Skipping zero-length gem: #{gemfile}")
169
168
  next
170
169
  end
171
170
 
@@ -179,7 +178,7 @@ module Gemirro
179
178
  exp << " (#{spec.original_name})" if
180
179
  spec.original_name != spec.full_name
181
180
  msg = "Skipping misnamed gem: #{gemfile} should be named #{exp}"
182
- logger.warn(msg)
181
+ Utils.logger.warn(msg)
183
182
  next
184
183
  end
185
184
 
@@ -189,13 +188,13 @@ module Gemirro
189
188
  spec
190
189
  rescue SignalException
191
190
  msg = 'Received signal, exiting'
192
- logger.error(msg)
191
+ Utils.logger.error(msg)
193
192
  raise
194
193
  rescue StandardError => e
195
194
  msg = ["Unable to process #{gemfile}",
196
195
  "#{e.message} (#{e.class})",
197
196
  "\t#{e.backtrace.join "\n\t"}"].join("\n")
198
- logger.debug(msg)
197
+ Utils.logger.debug(msg)
199
198
  end
200
199
  end.compact
201
200
  end
@@ -213,7 +212,7 @@ module Gemirro
213
212
  end
214
213
 
215
214
  if @updated_gems.empty?
216
- logger.info('No new gems')
215
+ Utils.logger.info('No new gems')
217
216
  terminate_interaction(0)
218
217
  end
219
218
 
@@ -236,7 +235,7 @@ module Gemirro
236
235
 
237
236
  compress_indicies
238
237
 
239
- logger.info("Updating production dir #{@dest_directory}") if verbose
238
+ Utils.logger.info("Updating production dir #{@dest_directory}") if verbose
240
239
  files << @specs_index
241
240
  files << "#{@specs_index}.gz"
242
241
  files << @latest_specs_index
@@ -296,25 +295,11 @@ module Gemirro
296
295
  dst_name,
297
296
  verbose: verbose,
298
297
  force: true)
299
- cache.flush_key(File.basename(dst_name))
300
- end
301
-
302
- ##
303
- # Cache class to store marshal and data into files
304
- #
305
- # @return [Gemirro::Cache]
306
- #
307
- def cache
308
- @cache ||= Gemirro::Cache
309
- .new(File.join(Gemirro.configuration.destination, '.cache'))
298
+ Utils.cache.flush_key(File.basename(dst_name))
310
299
  end
311
300
 
312
301
  def verbose
313
302
  @verbose ||= ::Gem.configuration.really_verbose
314
303
  end
315
-
316
- def logger
317
- Gemirro.configuration.logger
318
- end
319
304
  end
320
305
  end
@@ -19,9 +19,7 @@ module Gemirro
19
19
  # rubocop:enable Metrics/LineLength
20
20
 
21
21
  attr_accessor :versions_fetcher, :gems_fetcher
22
- attr_reader(:gems_orig_collection,
23
- :gems_source_collection,
24
- :stored_gems,
22
+ attr_reader(:stored_gems,
25
23
  :cache)
26
24
 
27
25
  # rubocop:disable Metrics/LineLength
@@ -75,7 +73,7 @@ module Gemirro
75
73
  # @return [nil]
76
74
  #
77
75
  get('/gem/:gemname') do
78
- gems = gems_collection
76
+ gems = Utils.gems_collection
79
77
  @gem = gems.find_by_name(params[:gemname])
80
78
  return not_found if @gem.nil?
81
79
 
@@ -89,7 +87,7 @@ module Gemirro
89
87
  # @return [nil]
90
88
  #
91
89
  get('/') do
92
- @gems = gems_collection
90
+ @gems = Utils.gems_collection
93
91
  erb(:index)
94
92
  end
95
93
 
@@ -130,16 +128,6 @@ module Gemirro
130
128
  send_file(resource)
131
129
  end
132
130
 
133
- ##
134
- # Cache class to store marshal and data into files
135
- #
136
- # @return [Gemirro::Cache]
137
- #
138
- def cache
139
- @cache ||= Gemirro::Cache
140
- .new(File.join(configuration.destination, '.cache'))
141
- end
142
-
143
131
  ##
144
132
  # Try to fetch gem and download its if it's possible, and
145
133
  # build and install indicies.
@@ -164,14 +152,15 @@ module Gemirro
164
152
  return if gems_fetcher.gemspec_exists?(gem.gemspec_filename(gem_version)) && gem_type == GEMSPEC_TYPE
165
153
  # rubocop:enable Metrics/LineLength
166
154
 
167
- logger.info("Try to download #{gem_name} with version #{gem_version}")
155
+ Utils.logger
156
+ .info("Try to download #{gem_name} with version #{gem_version}")
168
157
  gems_fetcher.source.gems.clear
169
158
  gems_fetcher.source.gems.push(gem)
170
159
  gems_fetcher.fetch
171
160
 
172
161
  update_indexes if configuration.update_on_fetch
173
162
  rescue StandardError => e
174
- logger.error(e)
163
+ Utils.logger.error(e)
175
164
  end
176
165
  end
177
166
 
@@ -185,13 +174,13 @@ module Gemirro
185
174
  indexer.only_origin = true
186
175
  indexer.ui = ::Gem::SilentUI.new
187
176
 
188
- configuration.logger.info('Generating indexes')
177
+ Utils.logger.info('Generating indexes')
189
178
  indexer.update_index
190
179
  indexer.updated_gems.peach do |gem|
191
- cache.flush_key(gem.name)
180
+ Utils.cache.flush_key(gem.name)
192
181
  end
193
182
  rescue SystemExit => e
194
- configuration.logger.info(e.message)
183
+ Utils.logger.info(e.message)
195
184
  end
196
185
 
197
186
  ##
@@ -226,50 +215,17 @@ module Gemirro
226
215
  params[:gems].to_s.split(',')
227
216
  end
228
217
 
229
- ##
230
- # @see Gemirro::Configuration#logger
231
- # @return [Logger]
232
- #
233
- def logger
234
- configuration.logger
235
- end
236
-
237
- ##
238
- # Generate Gems collection from Marshal dump
239
- #
240
- # @param [TrueClass|FalseClass] orig Fetch orig files
241
- # @return [Gemirro::GemVersionCollection]
242
- #
243
- def gems_collection(orig = true)
244
- return @gems_orig_collection if orig && !@gems_orig_collection.nil?
245
- return @gems_source_collection if !orig && !@gems_source_collection.nil?
246
-
247
- gems = []
248
- specs_files_paths(orig).pmap do |specs_file_path|
249
- cache.cache(File.basename(specs_file_path)) do
250
- # rubocop:disable Metrics/LineLength
251
- gems.concat(Marshal.load(Zlib::GzipReader.open(specs_file_path).read)) if File.exist?(specs_file_path)
252
- # rubocop:enable Metrics/LineLength
253
- end
254
- end
255
-
256
- collection = GemVersionCollection.new(gems)
257
- @gems_source_collection = collection unless orig
258
- @gems_orig_collection = collection if orig
259
-
260
- collection
261
- end
262
-
263
218
  ##
264
219
  # Return gems list from query params
265
220
  #
266
221
  # @return [Array]
267
222
  #
268
223
  def query_gems_list
269
- gems_collection(false) # load collection
224
+ Utils.gems_collection(false) # load collection
270
225
  gems = query_gems.pmap do |query_gem|
271
226
  gem_dependencies(query_gem)
272
227
  end
228
+
273
229
  gems.flatten!
274
230
  gems = gems.select do |g|
275
231
  !g.empty?
@@ -284,8 +240,8 @@ module Gemirro
284
240
  # @return [Array]
285
241
  #
286
242
  def gem_dependencies(gem_name)
287
- cache.cache(gem_name) do
288
- gems = gems_collection(false)
243
+ Utils.cache.cache(gem_name) do
244
+ gems = Utils.gems_collection(false)
289
245
  gem_collection = gems.find_by_name(gem_name)
290
246
 
291
247
  return '' if gem_collection.nil?
@@ -316,32 +272,6 @@ module Gemirro
316
272
  end
317
273
  end
318
274
 
319
- ##
320
- # Return specs fils paths
321
- #
322
- # @param [TrueClass|FalseClass] orig Fetch orig files
323
- # @return [Array]
324
- #
325
- def specs_files_paths(orig = true)
326
- marshal_version = Gemirro::Configuration.marshal_version
327
- specs_file_types.pmap do |specs_file_type|
328
- File.join(settings.public_folder,
329
- [specs_file_type,
330
- marshal_version,
331
- 'gz' + (orig ? '.orig' : '')
332
- ].join('.'))
333
- end
334
- end
335
-
336
- ##
337
- # Return specs fils types
338
- #
339
- # @return [Array]
340
- #
341
- def specs_file_types
342
- [:specs, :prerelease_specs]
343
- end
344
-
345
275
  ##
346
276
  # Try to cache gem classes
347
277
  #
@@ -25,21 +25,13 @@ module Gemirro
25
25
  @gems = gems
26
26
  end
27
27
 
28
- ##
29
- # @see Gemirro::Configuration#logger
30
- # @return [Logger]
31
- #
32
- def logger
33
- Gemirro.configuration.logger
34
- end
35
-
36
28
  ##
37
29
  # Fetches a list of all the available Gems and their versions.
38
30
  #
39
31
  # @return [String]
40
32
  #
41
33
  def fetch_versions
42
- logger.info(
34
+ Utils.logger.info(
43
35
  "Fetching #{Configuration.versions_file} on #{@name} (#{@host})"
44
36
  )
45
37
 
@@ -52,7 +44,7 @@ module Gemirro
52
44
  # @return [String]
53
45
  #
54
46
  def fetch_prerelease_versions
55
- logger.info(
47
+ Utils.logger.info(
56
48
  "Fetching #{Configuration.prerelease_versions_file}" \
57
49
  " on #{@name} (#{@host})"
58
50
  )
@@ -67,7 +59,7 @@ module Gemirro
67
59
  # @return [String]
68
60
  #
69
61
  def fetch_gem(name, version)
70
- logger.info(
62
+ Utils.logger.info(
71
63
  "Fetching gem #{name}, #{version} on #{@name} (#{@host})"
72
64
  )
73
65
  Http.get(host + "/gems/#{name}-#{version}.gem").body
@@ -81,7 +73,7 @@ module Gemirro
81
73
  # @return [String]
82
74
  #
83
75
  def fetch_gemspec(name, version)
84
- logger.info(
76
+ Utils.logger.info(
85
77
  "Fetching gemspec #{name}, #{version} on #{@name} (#{@host})"
86
78
  )
87
79
  marshal = Gemirro::Configuration.marshal_identifier
@@ -0,0 +1,85 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module Gemirro
4
+ ##
5
+ # The Utils class is responsible for executing specific traitments
6
+ # that are located at least on two other files
7
+ #
8
+ # @!attribute [r] client
9
+ # @return [HTTPClient]
10
+ #
11
+ class Utils
12
+ attr_reader :cache
13
+
14
+ ##
15
+ # Cache class to store marshal and data into files
16
+ #
17
+ # @return [Gemirro::Cache]
18
+ #
19
+ def self.cache
20
+ @cache ||= Gemirro::Cache
21
+ .new(File.join(configuration.destination, '.cache'))
22
+ end
23
+
24
+ ##
25
+ # Generate Gems collection from Marshal dump
26
+ #
27
+ # @param [TrueClass|FalseClass] orig Fetch orig files
28
+ # @return [Gemirro::GemVersionCollection]
29
+ #
30
+ def self.gems_collection(orig = true)
31
+ gems = []
32
+ specs_files_paths(orig).pmap do |specs_file_path|
33
+ next unless File.exist?(specs_file_path)
34
+ spec_gems = cache.cache(File.basename(specs_file_path)) do
35
+ Marshal.load(Zlib::GzipReader.open(specs_file_path).read)
36
+ end
37
+ gems.concat(spec_gems)
38
+ end
39
+
40
+ collection = GemVersionCollection.new(gems)
41
+ collection
42
+ end
43
+
44
+ ##
45
+ # Return specs fils paths
46
+ #
47
+ # @param [TrueClass|FalseClass] orig Fetch orig files
48
+ # @return [Array]
49
+ #
50
+ def self.specs_files_paths(orig = true)
51
+ marshal_version = Gemirro::Configuration.marshal_version
52
+ specs_file_types.pmap do |specs_file_type|
53
+ File.join(configuration.destination,
54
+ [specs_file_type,
55
+ marshal_version,
56
+ 'gz' + (orig ? '.orig' : '')
57
+ ].join('.'))
58
+ end
59
+ end
60
+
61
+ ##
62
+ # Return specs fils types
63
+ #
64
+ # @return [Array]
65
+ #
66
+ def self.specs_file_types
67
+ [:specs, :prerelease_specs]
68
+ end
69
+
70
+ ##
71
+ # @see Gemirro::Configuration#logger
72
+ # @return [Logger]
73
+ #
74
+ def self.logger
75
+ configuration.logger
76
+ end
77
+
78
+ ##
79
+ # @see Gemirro.configuration
80
+ #
81
+ def self.configuration
82
+ Gemirro.configuration
83
+ end
84
+ end
85
+ end
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # Gemirro Version
3
3
  module Gemirro
4
- VERSION = '0.12.0'
4
+ VERSION = '0.13.1'
5
5
  end
@@ -0,0 +1,33 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+ require 'gemirro/mirror_directory'
4
+ require 'gemirro/cache'
5
+
6
+ # Gem tests
7
+ module Gemirro
8
+ describe 'Cache' do
9
+ include FakeFS::SpecHelpers
10
+ before(:each) do
11
+ MirrorDirectory.new('/tmp')
12
+ @cache = Cache.new('/tmp')
13
+ end
14
+
15
+ it 'should play with flush key' do
16
+ @cache.cache('foo') do
17
+ 'something'
18
+ end
19
+ expect(@cache.cache('foo')).to eq('something')
20
+ @cache.flush_key('foo')
21
+ expect(@cache.cache('foo')).to be_nil
22
+ end
23
+
24
+ it 'should play with flush' do
25
+ @cache.cache('foo') do
26
+ 'something'
27
+ end
28
+ expect(@cache.cache('foo')).to eq('something')
29
+ @cache.flush
30
+ expect(@cache.cache('foo')).to be_nil
31
+ end
32
+ end
33
+ end
@@ -23,16 +23,8 @@ module Gemirro
23
23
  expect(@fetcher.versions_file).to be(@versions_file)
24
24
  end
25
25
 
26
- it 'should return configuration' do
27
- expect(@fetcher.configuration).to be(Gemirro.configuration)
28
- end
29
-
30
- it 'should return logger' do
31
- expect(@fetcher.logger).to be(Gemirro.configuration.logger)
32
- end
33
-
34
26
  it 'should test if gem exists' do
35
- @fetcher.configuration.destination = './'
27
+ Utils.configuration.destination = './'
36
28
  expect(@fetcher.gem_exists?('test')).to be_falsy
37
29
  MirrorDirectory.new('./').add_directory('gems')
38
30
  MirrorDirectory.new('./').add_directory('quick/Marshal.4.8')
@@ -41,24 +33,24 @@ module Gemirro
41
33
  end
42
34
 
43
35
  it 'should ignore gem' do
44
- allow(@fetcher.logger).to receive(:info)
36
+ allow(Utils.logger).to receive(:info)
45
37
  .once.with('Fetching gemirro-0.0.1.gem')
46
38
  expect(@fetcher.ignore_gem?('gemirro', '0.0.1')).to be_falsy
47
- @fetcher.configuration.ignore_gem('gemirro', '0.0.1')
39
+ Utils.configuration.ignore_gem('gemirro', '0.0.1')
48
40
  expect(@fetcher.ignore_gem?('gemirro', '0.0.1')).to be_truthy
49
41
  end
50
42
 
51
43
  it 'should log error when fetch gem failed' do
52
- allow(@fetcher.logger).to receive(:info)
44
+ allow(Utils.logger).to receive(:info)
53
45
  .once.with('Fetching gemirro-0.0.1.gem')
54
46
  gem = Gem.new('gemirro')
55
47
  version = ::Gem::Version.new('0.0.1')
56
- @fetcher.configuration.ignore_gem('gemirro', '0.0.1')
48
+ Utils.configuration.ignore_gem('gemirro', '0.0.1')
57
49
  allow(@source).to receive(:fetch_gem)
58
50
  .once.with('gemirro', version).and_raise(ArgumentError)
59
- allow(@fetcher.logger).to receive(:error)
51
+ allow(Utils.logger).to receive(:error)
60
52
  .once.with(/Failed to retrieve/)
61
- allow(@fetcher.logger).to receive(:debug)
53
+ allow(Utils.logger).to receive(:debug)
62
54
  .once.with(/Adding (.*) to the list of ignored Gems/)
63
55
 
64
56
  expect(@fetcher.fetch_gem(gem, version)).to be_nil
@@ -66,7 +58,7 @@ module Gemirro
66
58
  end
67
59
 
68
60
  it 'should fetch gem' do
69
- allow(@fetcher.logger).to receive(:info)
61
+ allow(Utils.logger).to receive(:info)
70
62
  .once.with('Fetching gemirro-0.0.1.gem')
71
63
  MirrorDirectory.new('./').add_directory('gems')
72
64
  gem = Gem.new('gemirro')
@@ -78,7 +70,7 @@ module Gemirro
78
70
  end
79
71
 
80
72
  it 'should fetch gemspec' do
81
- allow(@fetcher.logger).to receive(:info)
73
+ allow(Utils.logger).to receive(:info)
82
74
  .once.with('Fetching gemirro-0.0.1.gemspec.rz')
83
75
  MirrorDirectory.new('./').add_directory('quick/Marshal.4.8')
84
76
  gem = Gem.new('gemirro')
@@ -91,12 +83,12 @@ module Gemirro
91
83
  end
92
84
 
93
85
  it 'should not fetch gemspec if file exists' do
94
- allow(@fetcher.logger).to receive(:info)
86
+ allow(Utils.logger).to receive(:info)
95
87
  .once.with('Fetching gemirro-0.0.1.gemspec.rz')
96
88
  allow(@fetcher).to receive(:gemspec_exists?)
97
89
  .once.with('gemirro-0.0.1.gemspec.rz')
98
90
  .and_return(true)
99
- allow(@fetcher.logger).to receive(:debug)
91
+ allow(Utils.logger).to receive(:debug)
100
92
  .once.with('Skipping gemirro-0.0.1.gemspec.rz')
101
93
 
102
94
  gem = Gem.new('gemirro')
@@ -120,7 +112,7 @@ module Gemirro
120
112
  allow(gem.requirement).to receive(:satisfied_by?)
121
113
  .once.with(nil).and_return(false)
122
114
  @fetcher.source.gems << gem
123
- allow(@fetcher.logger).to receive(:debug)
115
+ allow(Utils.logger).to receive(:debug)
124
116
  .once.with('Skipping gemirro-0.0.1.gem')
125
117
  expect(@fetcher.fetch).to eq([gem])
126
118
  end
@@ -137,9 +129,9 @@ module Gemirro
137
129
  allow(@fetcher).to receive(:fetch_gem)
138
130
  .once.with(gem, nil).and_return('gemfile')
139
131
 
140
- allow(@fetcher.configuration.mirror_gems_directory).to receive(:add_file)
132
+ allow(Utils.configuration.mirror_gems_directory).to receive(:add_file)
141
133
  .once.with('gemirro-0.0.2.gem', 'gemfile')
142
- allow(@fetcher.configuration.mirror_gemspecs_directory)
134
+ allow(Utils.configuration.mirror_gemspecs_directory)
143
135
  .to receive(:add_file)
144
136
  .once.with('gemirro-0.0.1.gemspec.rz', 'gemfile')
145
137
  expect(@fetcher.fetch).to eq([gem, gemspec])
@@ -3,6 +3,7 @@ require 'rack/test'
3
3
  require 'json'
4
4
  require 'pmap'
5
5
  require 'gemirro/cache'
6
+ require 'gemirro/utils'
6
7
  require 'gemirro/mirror_directory'
7
8
  require 'gemirro/mirror_file'
8
9
  require 'gemirro/gem_version_collection'
@@ -33,6 +34,7 @@ module Gemirro
33
34
  MirrorDirectory.new('/').add_directory('tmp')
34
35
  MirrorFile.new('/var/www/gemirro/test').write('content')
35
36
  Gemirro.configuration.destination = '/var/www/gemirro'
37
+ Utils.instance_eval('@cache = nil')
36
38
  FakeFS::FileSystem.clone(Gemirro::Configuration.views_directory)
37
39
  end
38
40
 
@@ -255,11 +257,12 @@ module Gemirro
255
257
 
256
258
  gem = Gemirro::GemVersion.new('volay', '0.1.0', 'ruby')
257
259
  collection = Gemirro::GemVersionCollection.new([gem])
258
- allow_any_instance_of(Gemirro::Server).to receive(:gems_collection)
260
+ allow(Utils).to receive(:gems_collection)
259
261
  .and_return(collection)
260
262
  get '/api/v1/dependencies.json?gems=volay'
261
263
  expect(last_response.headers['Content-Type'])
262
264
  .to eq('application/json')
265
+
263
266
  expect(last_response.body).to match(/"name":"volay"/)
264
267
  expect(last_response).to be_ok
265
268
  end
@@ -1,6 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require 'spec_helper'
3
3
  require 'gemirro/http'
4
+ require 'gemirro/utils'
4
5
  require 'gemirro/source'
5
6
 
6
7
  # Source tests
@@ -8,7 +9,7 @@ module Gemirro
8
9
  describe 'Source' do
9
10
  before(:each) do
10
11
  @source = Source.new('RubyGems', 'https://rubygems.org')
11
- allow(@source.logger).to receive(:info)
12
+ allow(Utils.logger).to receive(:info)
12
13
  end
13
14
 
14
15
  it 'should be initialized' do
data/task/rspec.rake CHANGED
@@ -2,5 +2,5 @@ require 'rspec/core/rake_task'
2
2
 
3
3
  desc 'Run Rspec tests'
4
4
  RSpec::Core::RakeTask.new(:spec) do |t|
5
- t.rspec_opts = '--color --format documentation'
5
+ t.rspec_opts = '--color --format documentation --backtrace'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gemirro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.13.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre Rambaud
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-05 00:00:00.000000000 Z
11
+ date: 2015-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slop
@@ -170,14 +170,14 @@ dependencies:
170
170
  requirements:
171
171
  - - "~>"
172
172
  - !ruby/object:Gem::Version
173
- version: '0.30'
173
+ version: '0.35'
174
174
  type: :development
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - "~>"
179
179
  - !ruby/object:Gem::Version
180
- version: '0.30'
180
+ version: '0.35'
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: fakefs
183
183
  requirement: !ruby/object:Gem::Requirement
@@ -214,6 +214,7 @@ files:
214
214
  - lib/gemirro/cli.rb
215
215
  - lib/gemirro/cli/index.rb
216
216
  - lib/gemirro/cli/init.rb
217
+ - lib/gemirro/cli/list.rb
217
218
  - lib/gemirro/cli/server.rb
218
219
  - lib/gemirro/cli/update.rb
219
220
  - lib/gemirro/configuration.rb
@@ -227,11 +228,13 @@ files:
227
228
  - lib/gemirro/mirror_file.rb
228
229
  - lib/gemirro/server.rb
229
230
  - lib/gemirro/source.rb
231
+ - lib/gemirro/utils.rb
230
232
  - lib/gemirro/version.rb
231
233
  - lib/gemirro/versions_fetcher.rb
232
234
  - lib/gemirro/versions_file.rb
233
235
  - spec/fixtures/gems/gemirro-0.0.1.gem
234
236
  - spec/fixtures/quick/gemirro-0.0.1.gemspec.rz
237
+ - spec/gemirro/cache_spec.rb
235
238
  - spec/gemirro/cli_spec.rb
236
239
  - spec/gemirro/configuration_spec.rb
237
240
  - spec/gemirro/gem_spec.rb
@@ -291,4 +294,3 @@ signing_key:
291
294
  specification_version: 4
292
295
  summary: Gem for easily creating your own gems mirror.
293
296
  test_files: []
294
- has_rdoc: