Object
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 15 15: def initialize(options = {}) 16: @options = options 17: @remotes = (options["remotes"] || []).map { |r| normalize_uri(r) } 18: @allow_remote = false 19: @allow_cached = false 20: 21: # Hardcode the paths for now 22: @caches = [ Bundler.app_cache ] + Bundler.rubygems.gem_path.map do |x| 23: File.expand_path("#{x}/cache") 24: end 25: 26: @spec_fetch_map = {} 27: end
# File lib/bundler/source.rb, line 130 130: def add_remote(source) 131: @remotes << normalize_uri(source) 132: end
# File lib/bundler/source.rb, line 122 122: def cache(spec) 123: cached_path = cached_gem(spec) 124: raise GemNotFound, "Missing gem file '#{spec.full_name}.gem'." unless cached_path 125: return if File.dirname(cached_path) == Bundler.app_cache.to_s 126: Bundler.ui.info " * #{File.basename(cached_path)}" 127: FileUtils.cp(cached_path, Bundler.app_cache) 128: 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 73 73: def fetch(spec) 74: spec, uri = @spec_fetch_map[spec.full_name] 75: if spec 76: path = download_gem_from_uri(spec, uri) 77: s = Bundler.rubygems.spec_from_gem(path) 78: spec.__swap__(s) 79: end 80: end
# File lib/bundler/source.rb, line 37 37: def hash 38: Rubygems.hash 39: end
# File lib/bundler/source.rb, line 82 82: def install(spec) 83: if installed_specs[spec].any? 84: Bundler.ui.info "Using #{spec.name} (#{spec.version}) " 85: return 86: end 87: 88: Bundler.ui.info "Installing #{spec.name} (#{spec.version}) " 89: path = cached_gem(spec) 90: 91: Bundler.rubygems.preserve_paths do 92: 93: install_path = Bundler.requires_sudo? ? Bundler.tmp : Bundler.rubygems.gem_dir 94: options = { :install_dir => install_path, 95: :ignore_dependencies => true, 96: :wrappers => true, 97: :env_shebang => true } 98: options.merge!(:bin_dir => "#{install_path}/bin") unless spec.executables.nil? || spec.executables.empty? 99: 100: installer = Gem::Installer.new path, options 101: installer.install 102: end 103: 104: # SUDO HAX 105: if Bundler.requires_sudo? 106: sudo "mkdir -p #{Bundler.rubygems.gem_dir}/gems #{Bundler.rubygems.gem_dir}/specifications" 107: sudo "cp -R #{Bundler.tmp}/gems/#{spec.full_name} #{Bundler.rubygems.gem_dir}/gems/" 108: sudo "cp -R #{Bundler.tmp}/specifications/#{spec.full_name}.gemspec #{Bundler.rubygems.gem_dir}/specifications/" 109: spec.executables.each do |exe| 110: sudo "mkdir -p #{Bundler.rubygems.gem_bindir}" 111: sudo "cp -R #{Bundler.tmp}/bin/#{exe} #{Bundler.rubygems.gem_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 134 134: def merge_remotes(source) 135: @remotes = [] 136: source.remotes.each do |r| 137: add_remote r.to_s 138: end 139: 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 69 69: def specs 70: @specs ||= fetch_specs 71: end
# File lib/bundler/source.rb, line 118 118: def sudo(str) 119: Bundler.sudo(str) 120: 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 198 198: def cached_specs 199: @cached_specs ||= begin 200: idx = installed_specs.dup 201: 202: path = Bundler.app_cache 203: Dir["#{path}/*.gem"].each do |gemfile| 204: next if gemfile =~ /^bundler\-[\d\.]+?\.gem/ 205: 206: begin 207: s ||= Bundler.rubygems.spec_from_gem(gemfile) 208: rescue Gem::Package::FormatError 209: raise GemspecError, "Could not read gem at #{gemfile}. It may be corrupted." 210: end 211: 212: s.source = self 213: idx << s 214: end 215: end 216: 217: idx 218: end
# File lib/bundler/source.rb, line 259 259: def download_gem_from_uri(spec, uri) 260: spec.fetch_platform 261: 262: download_path = Bundler.requires_sudo? ? Bundler.tmp : Bundler.rubygems.gem_dir 263: gem_path = "#{Bundler.rubygems.gem_dir}/cache/#{spec.full_name}.gem" 264: 265: FileUtils.mkdir_p("#{download_path}/cache") 266: Bundler.rubygems.download_gem(spec, uri, download_path) 267: 268: if Bundler.requires_sudo? 269: sudo "mkdir -p #{Bundler.rubygems.gem_dir}/cache" 270: sudo "mv #{Bundler.tmp}/cache/#{spec.full_name}.gem #{gem_path}" 271: end 272: 273: gem_path 274: end
# File lib/bundler/source.rb, line 244 244: def fetch_all_remote_specs(&blk) 245: begin 246: # Fetch all specs, minus prerelease specs 247: Gem::SpecFetcher.new.list(true, false).each(&blk) 248: # Then fetch the prerelease specs 249: begin 250: Gem::SpecFetcher.new.list(false, true).each(&blk) 251: rescue Gem::RemoteFetcher::FetchError 252: Bundler.ui.warn "Could not fetch prerelease specs from #{self}" 253: end 254: rescue Gem::RemoteFetcher::FetchError 255: Bundler.ui.warn "Could not reach #{self}" 256: end 257: end
# File lib/bundler/source.rb, line 160 160: def fetch_specs 161: Index.build do |idx| 162: idx.use installed_specs 163: idx.use cached_specs if @allow_cached || @allow_remote 164: idx.use remote_specs if @allow_remote 165: end 166: end
# File lib/bundler/source.rb, line 168 168: def installed_specs 169: @installed_specs ||= begin 170: idx = Index.new 171: have_bundler = false 172: Bundler.rubygems.all_specs.reverse.each do |spec| 173: next if spec.name == 'bundler' && spec.version.to_s != VERSION 174: have_bundler = true if spec.name == 'bundler' 175: spec.source = self 176: idx << spec 177: end 178: 179: # Always have bundler locally 180: unless have_bundler 181: # We're running bundler directly from the source 182: # so, let's create a fake gemspec for it (it's a path) 183: # gemspec 184: bundler = Gem::Specification.new do |s| 185: s.name = 'bundler' 186: s.version = VERSION 187: s.platform = Gem::Platform::RUBY 188: s.source = self 189: s.authors = ["bundler team"] 190: s.loaded_from = File.expand_path("..", __FILE__) 191: end 192: idx << bundler 193: end 194: idx 195: end 196: 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 220 220: def remote_specs 221: @remote_specs ||= begin 222: idx = Index.new 223: old = Bundler.rubygems.sources 224: 225: remotes.each do |uri| 226: Bundler.ui.info "Fetching source index for #{uri}" 227: Gem.sources = ["#{uri}"] 228: fetch_all_remote_specs do |n,v| 229: v.each do |name, version, platform| 230: next if name == 'bundler' 231: spec = RemoteSpecification.new(name, version, platform, uri) 232: spec.source = self 233: @spec_fetch_map[spec.full_name] = [spec, uri] 234: idx << spec 235: end 236: end 237: end 238: idx 239: ensure 240: Bundler.rubygems.sources = old 241: end 242: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.