TODO: Refactor this class
# File lib/bundler/source.rb, line 51 51: def self.from_lock(options) 52: s = new(options) 53: Array(options["remote"]).each { |r| s.add_remote(r) } 54: s 55: end
# File lib/bundler/source.rb, line 18 18: def initialize(options = {}) 19: @options = options 20: @remotes = (options["remotes"] || []).map { |r| normalize_uri(r) } 21: @fetchers = {} 22: @allow_remote = false 23: @allow_cached = false 24: 25: @caches = [ Bundler.app_cache ] + 26: Bundler.rubygems.gem_path.map{|p| File.expand_path("#{p}/cache") } 27: end
# File lib/bundler/source.rb, line 126 126: def add_remote(source) 127: @remotes << normalize_uri(source) 128: end
# File lib/bundler/source.rb, line 118 118: def cache(spec) 119: cached_path = cached_gem(spec) 120: raise GemNotFound, "Missing gem file '#{spec.full_name}.gem'." unless cached_path 121: return if File.dirname(cached_path) == Bundler.app_cache.to_s 122: Bundler.ui.info " * #{File.basename(cached_path)}" 123: FileUtils.cp(cached_path, Bundler.app_cache) 124: end
# File lib/bundler/source.rb, line 33 33: def cached! 34: @allow_cached = true 35: end
# File lib/bundler/source.rb, line 41 41: def eql?(o) 42: Rubygems === o 43: end
# File lib/bundler/source.rb, line 37 37: def hash 38: Rubygems.hash 39: end
# File lib/bundler/source.rb, line 73 73: def install(spec) 74: if installed_specs[spec].any? 75: Bundler.ui.info "Using #{spec.name} (#{spec.version}) " 76: return 77: end 78: 79: Bundler.ui.info "Installing #{spec.name} (#{spec.version}) " 80: path = cached_gem(spec) 81: if Bundler.requires_sudo? 82: install_path = Bundler.tmp 83: bin_path = install_path.join("bin") 84: else 85: install_path = Bundler.rubygems.gem_dir 86: bin_path = Bundler.system_bindir 87: end 88: 89: Bundler.rubygems.preserve_paths do 90: Bundler::GemInstaller.new(path, 91: :install_dir => install_path.to_s, 92: :bin_dir => bin_path.to_s, 93: :ignore_dependencies => true, 94: :wrappers => true, 95: :env_shebang => true 96: ).install 97: end 98: 99: if spec.post_install_message 100: Installer.post_install_messages[spec.name] = spec.post_install_message 101: end 102: 103: # SUDO HAX 104: if Bundler.requires_sudo? 105: Bundler.mkdir_p "#{Bundler.rubygems.gem_dir}/gems" 106: Bundler.mkdir_p "#{Bundler.rubygems.gem_dir}/specifications" 107: Bundler.sudo "cp -R #{Bundler.tmp}/gems/#{spec.full_name} #{Bundler.rubygems.gem_dir}/gems/" 108: Bundler.sudo "cp -R #{Bundler.tmp}/specifications/#{spec.full_name}.gemspec #{Bundler.rubygems.gem_dir}/specifications/" 109: spec.executables.each do |exe| 110: Bundler.mkdir_p Bundler.system_bindir 111: Bundler.sudo "cp -R #{Bundler.tmp}/bin/#{exe} #{Bundler.system_bindir}" 112: end 113: end 114: 115: spec.loaded_from = "#{Bundler.rubygems.gem_dir}/specifications/#{spec.full_name}.gemspec" 116: end
# File lib/bundler/source.rb, line 47 47: def options 48: { "remotes" => @remotes.map { |r| r.to_s } } 49: end
# File lib/bundler/source.rb, line 29 29: def remote! 30: @allow_remote = true 31: end
# File lib/bundler/source.rb, line 130 130: def replace_remotes(source) 131: return false if source.remotes == @remotes 132: 133: @remotes = [] 134: source.remotes.each do |r| 135: add_remote r.to_s 136: end 137: 138: true 139: end
# File lib/bundler/source.rb, line 69 69: def specs 70: @specs ||= fetch_specs 71: end
# File lib/bundler/source.rb, line 57 57: def to_lock 58: out = "GEM\n" 59: out << remotes.map {|r| " remote: #{r}\n" }.join 60: out << " specs:\n" 61: end
# File lib/bundler/source.rb, line 63 63: def to_s 64: remote_names = self.remotes.map { |r| r.to_s }.join(', ') 65: "rubygems repository #{remote_names}" 66: end
# File lib/bundler/source.rb, line 143 143: def cached_gem(spec) 144: possibilities = @caches.map { |p| "#{p}/#{spec.file_name}" } 145: cached_gem = possibilities.find { |p| File.exist?(p) } 146: unless cached_gem 147: raise Bundler::GemNotFound, "Could not find #{spec.file_name} for installation" 148: end 149: cached_gem 150: end
# File lib/bundler/source.rb, line 204 204: def cached_specs 205: @cached_specs ||= begin 206: idx = installed_specs.dup 207: 208: path = Bundler.app_cache 209: Dir["#{path}/*.gem"].each do |gemfile| 210: next if gemfile =~ /^bundler\-[\d\.]+?\.gem/ 211: 212: begin 213: s ||= Bundler.rubygems.spec_from_gem(gemfile) 214: rescue Gem::Package::FormatError 215: raise GemspecError, "Could not read gem at #{gemfile}. It may be corrupted." 216: end 217: 218: s.source = self 219: idx << s 220: end 221: end 222: 223: idx 224: end
# File lib/bundler/source.rb, line 160 160: def fetch_specs 161: # remote_specs usually generates a way larger Index than the other 162: # sources, and large_idx.use small_idx is way faster than 163: # small_idx.use large_idx. 164: if @allow_remote 165: idx = remote_specs.dup 166: else 167: idx = Index.new 168: end 169: idx.use(cached_specs, :override_dupes) if @allow_cached || @allow_remote 170: idx.use(installed_specs, :override_dupes) 171: idx 172: end
# File lib/bundler/source.rb, line 174 174: def installed_specs 175: @installed_specs ||= begin 176: idx = Index.new 177: have_bundler = false 178: Bundler.rubygems.all_specs.reverse.each do |spec| 179: next if spec.name == 'bundler' && spec.version.to_s != VERSION 180: have_bundler = true if spec.name == 'bundler' 181: spec.source = self 182: idx << spec 183: end 184: 185: # Always have bundler locally 186: unless have_bundler 187: # We're running bundler directly from the source 188: # so, let's create a fake gemspec for it (it's a path) 189: # gemspec 190: bundler = Gem::Specification.new do |s| 191: s.name = 'bundler' 192: s.version = VERSION 193: s.platform = Gem::Platform::RUBY 194: s.source = self 195: s.authors = ["bundler team"] 196: s.loaded_from = File.expand_path("..", __FILE__) 197: end 198: idx << bundler 199: end 200: idx 201: end 202: end
# File lib/bundler/source.rb, line 152 152: def normalize_uri(uri) 153: uri = uri.to_s 154: uri = "#{uri}/" unless uri =~ %/$' 155: uri = URI(uri) 156: raise ArgumentError, "The source must be an absolute URI" unless uri.absolute? 157: uri 158: end
# File lib/bundler/source.rb, line 226 226: def remote_specs 227: @remote_specs ||= begin 228: idx = Index.new 229: old = Bundler.rubygems.sources 230: 231: sources = {} 232: remotes.each do |uri| 233: fetcher = Bundler::Fetcher.new(uri) 234: specs = fetcher.specs(dependency_names, self) 235: sources[fetcher] = specs.size 236: 237: idx.use specs 238: end 239: 240: # don't need to fetch all specifications for every gem/version on 241: # the rubygems repo if there's no api endpoints to search over 242: # or it has too many specs to fetch 243: fetchers = sources.keys 244: api_fetchers = fetchers.select {|fetcher| fetcher.has_api } 245: modern_index_fetchers = fetchers - api_fetchers 246: if api_fetchers.any? && modern_index_fetchers.all? {|fetcher| sources[fetcher] < FORCE_MODERN_INDEX_LIMIT } 247: # this will fetch all the specifications on the rubygems repo 248: unmet_dependency_names = idx.unmet_dependency_names 249: unmet_dependency_names -= ['bundler'] # bundler will always be unmet 250: 251: Bundler.ui.debug "Unmet Dependencies: #{unmet_dependency_names}" 252: if unmet_dependency_names.any? 253: api_fetchers.each do |fetcher| 254: idx.use fetcher.specs(unmet_dependency_names, self) 255: end 256: end 257: else 258: Bundler::Fetcher.disable_endpoint = true 259: api_fetchers.each {|fetcher| idx.use fetcher.specs([], self) } 260: end 261: 262: idx 263: ensure 264: Bundler.rubygems.sources = old 265: end 266: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.