Class: Bundler::Source::Rubygems
- Inherits:
-
Bundler::Source
- Object
- Bundler::Source
- Bundler::Source::Rubygems
- Defined in:
- lib/bundler/source/rubygems.rb,
lib/bundler/source/rubygems/remote.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Remote
Constant Summary collapse
- API_REQUEST_LIMIT =
Use the API when installing less than X gems
500
- API_REQUEST_SIZE =
Ask for X gems per API request
50
Instance Attribute Summary collapse
-
#caches ⇒ Object
readonly
Returns the value of attribute caches.
-
#remotes ⇒ Object
readonly
Returns the value of attribute remotes.
Attributes inherited from Bundler::Source
Class Method Summary collapse
Instance Method Summary collapse
- #add_remote(source) ⇒ Object
- #allow_multisource! ⇒ Object
- #cache(spec, custom_path = nil) ⇒ Object
- #cached! ⇒ Object
- #cached_built_in_gem(spec) ⇒ Object
- #can_lock?(spec) ⇒ Boolean
- #dependency_names_to_double_check ⇒ Object
- #disable_multisource? ⇒ Boolean
- #double_check_for(unmet_dependency_names) ⇒ Object
- #eql?(other) ⇒ Boolean (also: #==)
- #equivalent_remotes?(other_remotes) ⇒ Boolean
- #fetchers ⇒ Object
- #hash ⇒ Object
- #include?(o) ⇒ Boolean
-
#initialize(options = {}) ⇒ Rubygems
constructor
A new instance of Rubygems.
- #install(spec, opts = {}) ⇒ Object
- #options ⇒ Object
- #remote! ⇒ Object
- #replace_remotes(other_remotes, allow_equivalent = false) ⇒ Object
- #specs ⇒ Object
- #to_lock ⇒ Object
- #to_s ⇒ Object (also: #name)
- #unmet_deps ⇒ Object
Methods inherited from Bundler::Source
#extension_cache_path, #inspect, #path?, #version_message
Constructor Details
#initialize(options = {}) ⇒ Rubygems
Returns a new instance of Rubygems.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/bundler/source/rubygems.rb', line 17 def initialize( = {}) @options = @remotes = [] @dependency_names = [] @allow_remote = false @allow_cached = false @caches = [cache_path, *Bundler.rubygems.gem_cache] @disable_multisource = true Array(["remotes"] || []).reverse_each {|r| add_remote(r) } end |
Instance Attribute Details
#caches ⇒ Object (readonly)
Returns the value of attribute caches.
15 16 17 |
# File 'lib/bundler/source/rubygems.rb', line 15 def caches @caches end |
#remotes ⇒ Object (readonly)
Returns the value of attribute remotes.
15 16 17 |
# File 'lib/bundler/source/rubygems.rb', line 15 def remotes @remotes end |
Class Method Details
.from_lock(options) ⇒ Object
70 71 72 |
# File 'lib/bundler/source/rubygems.rb', line 70 def self.from_lock() new() end |
Instance Method Details
#add_remote(source) ⇒ Object
233 234 235 236 |
# File 'lib/bundler/source/rubygems.rb', line 233 def add_remote(source) uri = normalize_uri(source) @remotes.unshift(uri) unless @remotes.include?(uri) end |
#allow_multisource! ⇒ Object
57 58 59 |
# File 'lib/bundler/source/rubygems.rb', line 57 def allow_multisource! @disable_multisource = false end |
#cache(spec, custom_path = nil) ⇒ Object
205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/bundler/source/rubygems.rb', line 205 def cache(spec, custom_path = nil) if builtin_gem?(spec) cached_path = cached_built_in_gem(spec) else cached_path = cached_gem(spec) end raise GemNotFound, "Missing gem file '#{spec.full_name}.gem'." unless cached_path return if File.dirname(cached_path) == Bundler.app_cache.to_s Bundler.ui.info " * #{File.basename(cached_path)}" FileUtils.cp(cached_path, Bundler.app_cache(custom_path)) rescue Errno::EACCES => e Bundler.ui.debug(e) raise InstallError, e. end |
#cached! ⇒ Object
34 35 36 37 |
# File 'lib/bundler/source/rubygems.rb', line 34 def cached! @specs = nil @allow_cached = true end |
#cached_built_in_gem(spec) ⇒ Object
220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/bundler/source/rubygems.rb', line 220 def cached_built_in_gem(spec) cached_path = cached_path(spec) if cached_path.nil? remote_spec = remote_specs.search(spec).first if remote_spec cached_path = fetch_gem(remote_spec) else Bundler.ui.warn "#{spec.full_name} is built in to Ruby, and can't be cached because your Gemfile doesn't have any sources that contain it." end end cached_path end |
#can_lock?(spec) ⇒ Boolean
61 62 63 64 |
# File 'lib/bundler/source/rubygems.rb', line 61 def can_lock?(spec) return super if disable_multisource? spec.source.is_a?(Rubygems) end |
#dependency_names_to_double_check ⇒ Object
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
# File 'lib/bundler/source/rubygems.rb', line 289 def dependency_names_to_double_check names = [] remote_specs.each do |spec| case spec when EndpointSpecification, Gem::Specification, StubSpecification, LazySpecification names.concat(spec.runtime_dependencies) when RemoteSpecification # from the full index return nil else raise "unhandled spec type (#{spec.inspect})" end end names.map!(&:name) if names names end |
#disable_multisource? ⇒ Boolean
53 54 55 |
# File 'lib/bundler/source/rubygems.rb', line 53 def disable_multisource? @disable_multisource end |
#double_check_for(unmet_dependency_names) ⇒ Object
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/bundler/source/rubygems.rb', line 270 def double_check_for(unmet_dependency_names) return unless @allow_remote return unless api_fetchers.any? unmet_dependency_names = unmet_dependency_names.call unless unmet_dependency_names.nil? if api_fetchers.size <= 1 # can't do this when there are multiple fetchers because then we might not fetch from _all_ # of them unmet_dependency_names -= remote_specs.spec_names # avoid re-fetching things we've already gotten end return if unmet_dependency_names.empty? end Bundler.ui.debug "Double checking for #{unmet_dependency_names || "all specs (due to the size of the request)"} in #{self}" fetch_names(api_fetchers, unmet_dependency_names, specs, false) end |
#eql?(other) ⇒ Boolean Also known as: ==
43 44 45 |
# File 'lib/bundler/source/rubygems.rb', line 43 def eql?(other) other.is_a?(Rubygems) && other.credless_remotes == credless_remotes end |
#equivalent_remotes?(other_remotes) ⇒ Boolean
238 239 240 |
# File 'lib/bundler/source/rubygems.rb', line 238 def equivalent_remotes?(other_remotes) other_remotes.map(&method(:remove_auth)) == @remotes.map(&method(:remove_auth)) end |
#fetchers ⇒ Object
263 264 265 266 267 268 |
# File 'lib/bundler/source/rubygems.rb', line 263 def fetchers @fetchers ||= remotes.map do |uri| remote = Source::Rubygems::Remote.new(uri) Bundler::Fetcher.new(remote) end end |
#hash ⇒ Object
39 40 41 |
# File 'lib/bundler/source/rubygems.rb', line 39 def hash @remotes.hash end |
#include?(o) ⇒ Boolean
49 50 51 |
# File 'lib/bundler/source/rubygems.rb', line 49 def include?(o) o.is_a?(Rubygems) && (o.credless_remotes - credless_remotes).empty? end |
#install(spec, opts = {}) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/bundler/source/rubygems.rb', line 104 def install(spec, opts = {}) force = opts[:force] ensure_builtin_gems_cached = opts[:ensure_builtin_gems_cached] if ensure_builtin_gems_cached && builtin_gem?(spec) if !cached_path(spec) cached_built_in_gem(spec) unless spec.remote force = true else spec.loaded_from = loaded_from(spec) end end if (installed?(spec) || Plugin.installed?(spec.name)) && !force "Using #{(spec)}" return nil # no post-install message end # Download the gem to get the spec, because some specs that are returned # by rubygems.org are broken and wrong. if spec.remote # Check for this spec from other sources uris = [spec.remote.anonymized_uri] uris += remotes_for_spec(spec).map(&:anonymized_uri) uris.uniq! Installer.ambiguous_gems << [spec.name, *uris] if uris.length > 1 path = fetch_gem(spec) begin s = Bundler.rubygems.spec_from_gem(path, Bundler.settings["trust-policy"]) spec.__swap__(s) rescue StandardError Bundler.rm_rf(path) raise end end unless Bundler.settings[:no_install] = "Installing #{(spec)}" += " with native extensions" if spec.extensions.any? Bundler.ui.confirm path = cached_gem(spec) if requires_sudo? install_path = Bundler.tmp(spec.full_name) bin_path = install_path.join("bin") else install_path = rubygems_dir bin_path = Bundler.system_bindir end Bundler.mkdir_p bin_path, :no_sudo => true unless spec.executables.empty? || Bundler.rubygems.provides?(">= 2.7.5") require_relative "../rubygems_gem_installer" installed_spec = Bundler::RubyGemsGemInstaller.at( path, :install_dir => install_path.to_s, :bin_dir => bin_path.to_s, :ignore_dependencies => true, :wrappers => true, :env_shebang => true, :build_args => opts[:build_args], :bundler_expected_checksum => spec.respond_to?(:checksum) && spec.checksum, :bundler_extension_cache_path => extension_cache_path(spec) ).install spec.full_gem_path = installed_spec.full_gem_path # SUDO HAX if requires_sudo? Bundler.rubygems.repository_subdirectories.each do |name| src = File.join(install_path, name, "*") dst = File.join(rubygems_dir, name) if name == "extensions" && Dir.glob(src).any? src = File.join(src, "*/*") ext_src = Dir.glob(src).first ext_src.gsub!(src[0..-6], "") dst = File.dirname(File.join(dst, ext_src)) end SharedHelpers.filesystem_access(dst) do |p| Bundler.mkdir_p(p) end Bundler.sudo "cp -R #{src} #{dst}" if Dir[src].any? end spec.executables.each do |exe| SharedHelpers.filesystem_access(Bundler.system_bindir) do |p| Bundler.mkdir_p(p) end Bundler.sudo "cp -R #{install_path}/bin/#{exe} #{Bundler.system_bindir}/" end end installed_spec.loaded_from = loaded_from(spec) end spec.loaded_from = loaded_from(spec) spec. ensure Bundler.rm_rf(install_path) if requires_sudo? end |
#options ⇒ Object
66 67 68 |
# File 'lib/bundler/source/rubygems.rb', line 66 def { "remotes" => @remotes.map(&:to_s) } end |
#remote! ⇒ Object
29 30 31 32 |
# File 'lib/bundler/source/rubygems.rb', line 29 def remote! @specs = nil @allow_remote = true end |
#replace_remotes(other_remotes, allow_equivalent = false) ⇒ Object
242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/bundler/source/rubygems.rb', line 242 def replace_remotes(other_remotes, allow_equivalent = false) return false if other_remotes == @remotes equivalent = allow_equivalent && equivalent_remotes?(other_remotes) @remotes = [] other_remotes.reverse_each do |r| add_remote r.to_s end !equivalent end |
#specs ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/bundler/source/rubygems.rb', line 92 def specs @specs ||= begin # remote_specs usually generates a way larger Index than the other # sources, and large_idx.use small_idx is way faster than # small_idx.use large_idx. idx = @allow_remote ? remote_specs.dup : Index.new idx.use(cached_specs, :override_dupes) if @allow_cached || @allow_remote idx.use(installed_specs, :override_dupes) idx end end |
#to_lock ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/bundler/source/rubygems.rb', line 74 def to_lock out = String.new("GEM\n") remotes.reverse_each do |remote| out << " remote: #{suppress_configured_credentials remote}\n" end out << " specs:\n" end |
#to_s ⇒ Object Also known as: name
82 83 84 85 86 87 88 89 |
# File 'lib/bundler/source/rubygems.rb', line 82 def to_s if remotes.empty? "locally installed gems" else remote_names = remotes.map(&:to_s).join(", ") "rubygems repository #{remote_names} or installed locally" end end |
#unmet_deps ⇒ Object
255 256 257 258 259 260 261 |
# File 'lib/bundler/source/rubygems.rb', line 255 def unmet_deps if @allow_remote && api_fetchers.any? remote_specs.unmet_dependency_names else [] end end |