Class: Geminabox::Server

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/geminabox/server.rb

Class Method Summary collapse

Class Method Details

.allow_delete?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/geminabox/server.rb', line 41

def allow_delete?
  allow_delete
end

.allow_upload?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/geminabox/server.rb', line 45

def allow_upload?
  allow_upload
end

.delegate_to_geminabox(*delegate_methods) ⇒ Object



10
11
12
# File 'lib/geminabox/server.rb', line 10

def self.delegate_to_geminabox(*delegate_methods)
  delegate_methods.each{|m| set m, Geminabox.send(m)}
end

.dependency_cacheObject



84
85
86
# File 'lib/geminabox/server.rb', line 84

def dependency_cache
  @dependency_cache ||= Geminabox::DiskCache.new(File.join(data, "_cache"))
end

.disallow_replace?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/geminabox/server.rb', line 37

def disallow_replace?
  ! allow_replace
end

.file_classObject

This method provides a test hook, as stubbing File is painful…



95
96
97
# File 'lib/geminabox/server.rb', line 95

def file_class
  @file_class ||= File
end

.file_class=(klass) ⇒ Object



99
100
101
# File 'lib/geminabox/server.rb', line 99

def file_class=(klass)
  @file_class = klass
end

.fixup_bundler_rubygems!Object



49
50
51
52
53
# File 'lib/geminabox/server.rb', line 49

def fixup_bundler_rubygems!
  return if @post_reset_hook_applied
  Gem.post_reset{ Gem::Specification.all = nil } if defined? Bundler and Gem.respond_to? :post_reset
  @post_reset_hook_applied = true
end

.indexerObject



80
81
82
# File 'lib/geminabox/server.rb', line 80

def indexer
  Gem::Indexer.new(data, :build_legacy => build_legacy)
end

.reindex(force_rebuild = false) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/geminabox/server.rb', line 55

def reindex(force_rebuild = false)
  fixup_bundler_rubygems!
  force_rebuild = true unless incremental_updates
  if force_rebuild
    indexer.generate_index
    dependency_cache.flush
  else
    begin
      require 'geminabox/indexer'
      updated_gemspecs = Geminabox::Indexer.updated_gemspecs(indexer)
      return if updated_gemspecs.empty?
      Geminabox::Indexer.patch_rubygems_update_index_pre_1_8_25(indexer)
      indexer.update_index
      updated_gemspecs.each { |gem| dependency_cache.flush_key(gem.name) }
    rescue Errno::ENOENT
      with_rlock { reindex(:force_rebuild) }
    rescue => e
      puts "#{e.class}:#{e.message}"
      puts e.backtrace.join("\n")
      with_rlock { reindex(:force_rebuild) }
    end
  end
rescue Gem::SystemExitException
end

.with_rlock(&block) ⇒ Object



88
89
90
91
92
# File 'lib/geminabox/server.rb', line 88

def with_rlock(&block)
  file_class.open(settings.lockfile, File::RDWR | File::CREAT) do |f|
    ReentrantFlock.synchronize(f, File::LOCK_EX | File::LOCK_NB, &block)
  end
end