class Geminabox::Server
Public Class Methods
allow_delete?()
click to toggle source
# File lib/geminabox/server.rb, line 36 def allow_delete? allow_delete end
delegate_to_geminabox(*delegate_methods)
click to toggle source
# File lib/geminabox/server.rb, line 6 def self.delegate_to_geminabox(*delegate_methods) delegate_methods.each{|m| set m, Geminabox.send(m)} end
dependency_cache()
click to toggle source
# File lib/geminabox/server.rb, line 74 def dependency_cache @dependency_cache ||= Geminabox::DiskCache.new(File.join(data, "_cache")) end
disallow_replace?()
click to toggle source
# File lib/geminabox/server.rb, line 32 def disallow_replace? ! allow_replace end
fixup_bundler_rubygems!()
click to toggle source
# File lib/geminabox/server.rb, line 40 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
indexer()
click to toggle source
# File lib/geminabox/server.rb, line 70 def indexer Gem::Indexer.new(data, :build_legacy => build_legacy) end
reindex(force_rebuild = false)
click to toggle source
# File lib/geminabox/server.rb, line 46 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) 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 reindex(:force_rebuild) rescue => e puts "#{e.class}:#{e.message}" puts e.backtrace.join("\n") reindex(:force_rebuild) end end rescue Gem::SystemExitException end
Private Instance Methods
all_gems()
click to toggle source
# File lib/geminabox/server.rb, line 218 def all_gems all_gems_with_duplicates.inject(:|) end
all_gems_with_duplicates()
click to toggle source
# File lib/geminabox/server.rb, line 222 def all_gems_with_duplicates specs_files_paths.map do |specs_file_path| if File.exists?(specs_file_path) Marshal.load(Gem.gunzip(Gem.read_binary(specs_file_path))) else [] end end end
api_request?()
click to toggle source
# File lib/geminabox/server.rb, line 192 def api_request? request.accept.first.to_s != "text/html" end
combined_gem_list()
click to toggle source
# File lib/geminabox/server.rb, line 270 def combined_gem_list GemListMerge.from(local_gem_list, remote_gem_list) end
default_platform()
click to toggle source
# File lib/geminabox/server.rb, line 285 def default_platform 'ruby' end
dependency_cache()
click to toggle source
# File lib/geminabox/server.rb, line 214 def dependency_cache self.class.dependency_cache end
error_response(code, message)
click to toggle source
# File lib/geminabox/server.rb, line 196 def error_response(code, message) halt [code, message] if api_request? html = <<HTML <html> <head><title>Error - #{code}</title></head> <body> <h1>Error - #{code}</h1> <p>#{message}</p> </body> </html> HTML halt [code, html] end
file_class()
click to toggle source
This method provides a test hook, as stubbing File is painful…
# File lib/geminabox/server.rb, line 174 def file_class File end
file_path()
click to toggle source
# File lib/geminabox/server.rb, line 210 def file_path File.expand_path(File.join(settings.data, *request.path_info)) end
gem_dependencies(gem_name)
click to toggle source
Return a list of versions of gem 'gem_name' with the dependencies of each version.
# File lib/geminabox/server.rb, line 290 def gem_dependencies(gem_name) dependency_cache.marshal_cache(gem_name) do load_gems. select { |gem| gem_name == gem.name }. map { |gem| [gem, spec_for(gem.name, gem.number, gem.platform)] }. reject { |(_, spec)| spec.nil? }. map do |(gem, spec)| { :name => gem.name, :number => gem.number.version, :platform => gem.platform, :dependencies => runtime_dependencies(spec) } end end end
gem_list()
click to toggle source
# File lib/geminabox/server.rb, line 254 def gem_list settings.rubygems_proxy ? combined_gem_list : local_gem_list end
handle_incoming_gem(gem)
click to toggle source
# File lib/geminabox/server.rb, line 178 def handle_incoming_gem(gem) begin GemStore.create(gem, params[:overwrite]) rescue GemStoreError => error error_response error.code, error.reason end if api_request? "Gem #{gem.name} received and indexed." else redirect url("/") end end
index_gems(gems)
click to toggle source
# File lib/geminabox/server.rb, line 250 def index_gems(gems) Set.new(gems.map{|gem| gem.name[0..0].downcase}) end
load_gems()
click to toggle source
# File lib/geminabox/server.rb, line 246 def load_gems @loaded_gems ||= Geminabox::GemVersionCollection.new(all_gems) end
local_gem_list()
click to toggle source
# File lib/geminabox/server.rb, line 262 def local_gem_list query_gems.map{|query_gem| gem_dependencies(query_gem) }.flatten(1) end
name_and_requirements_for(dep)
click to toggle source
# File lib/geminabox/server.rb, line 316 def name_and_requirements_for(dep) name = dep.name.kind_of?(Array) ? dep.name.first : dep.name [name, dep.requirement.to_s] end
query_gems()
click to toggle source
# File lib/geminabox/server.rb, line 258 def query_gems params[:gems].to_s.split(',') end
remote_gem_list()
click to toggle source
# File lib/geminabox/server.rb, line 266 def remote_gem_list RubygemsDependency.for(*query_gems) end
runtime_dependencies(spec)
click to toggle source
# File lib/geminabox/server.rb, line 309 def runtime_dependencies(spec) spec. dependencies. select { |dep| dep.type == :runtime }. map { |dep| name_and_requirements_for(dep) } end
serialize_update(&block)
click to toggle source
# File lib/geminabox/server.rb, line 160 def serialize_update(&block) with_lock(&block) rescue AlreadyLocked halt 503, { 'Retry-After' => settings.retry_interval }, 'Repository lock is held by another process' end
spec_file_name(specs_file_type)
click to toggle source
# File lib/geminabox/server.rb, line 242 def spec_file_name(specs_file_type) [specs_file_type, Gem.marshal_version, 'gz'].join('.') end
spec_for(gem_name, version, platform = default_platform)
click to toggle source
# File lib/geminabox/server.rb, line 275 def spec_for(gem_name, version, platform = default_platform) filename = [gem_name, version] filename.push(platform) if platform != default_platform spec_file = File.join(settings.data, "quick", "Marshal.#{Gem.marshal_version}", "#{filename.join("-")}.gemspec.rz") File::open(spec_file, 'r') do |unzipped_spec_file| unzipped_spec_file.binmode Marshal.load(Gem.inflate(unzipped_spec_file.read)) end if File.exists? spec_file end
specs_file_types()
click to toggle source
# File lib/geminabox/server.rb, line 232 def specs_file_types [:specs, :prerelease_specs] end
specs_files_paths()
click to toggle source
# File lib/geminabox/server.rb, line 236 def specs_files_paths specs_file_types.map do |specs_file_type| File.join(settings.data, spec_file_name(specs_file_type)) end end
with_lock() { || ... }
click to toggle source
# File lib/geminabox/server.rb, line 166 def with_lock file_class.open(settings.lockfile, File::RDWR | File::CREAT) do |f| raise AlreadyLocked unless f.flock(File::LOCK_EX | File::LOCK_NB) yield end end