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 more...
Direct Known Subclasses
Defined Under Namespace
Classes: Remote
Constant Summary collapse
- API_REQUEST_SIZE =
Ask for X gems per API request
50
Instance Attribute Summary collapse
-
#remotes ⇒ Object
Returns the value of attribute remotes.
Attributes inherited from Bundler::Source
#checksum_store, #dependency_names
Class Method Summary collapse
Instance Method Summary collapse
- #add_remote(source) ⇒ Object
- #cache(spec, custom_path = nil) ⇒ Object
- #cached! ⇒ Object
- #cached_built_in_gem(spec, local: false) ⇒ Object
- #caches ⇒ Object
- #can_lock?(spec) ⇒ Boolean
- #dependency_api_available? ⇒ Boolean
- #dependency_names_to_double_check ⇒ Object
- #double_check_for(unmet_dependency_names) ⇒ Object
- #eql?(other) ⇒ Boolean (also: #==)
- #fetchers ⇒ Object
- #hash ⇒ Object
- #identifier ⇒ Object (also: #name, #to_gemfile)
- #include?(o) ⇒ Boolean
-
#initialize(options = {}) ⇒ Rubygems
constructor
A new instance of Rubygems.
- #install(spec, options = {}) ⇒ Object
- #local! ⇒ Object
- #local_only! ⇒ Object
- #local_only? ⇒ Boolean
- #multiple_remotes? ⇒ Boolean
- #no_remotes? ⇒ Boolean
- #options ⇒ Object
- #prefer_local! ⇒ Object
- #remote! ⇒ Object
- #remote_fetchers ⇒ Object
- #spec_names ⇒ Object
- #specs ⇒ Object
- #to_lock ⇒ Object
- #to_s ⇒ Object
- #unmet_deps ⇒ Object
Methods inherited from Bundler::Source
#add_dependency_names, #extension_cache_path, #inspect, #path?, #version_message
Constructor Details
permalink #initialize(options = {}) ⇒ Rubygems
Returns a new instance of Rubygems.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/bundler/source/rubygems.rb', line 15 def initialize( = {}) @options = @remotes = [] @dependency_names = [] @allow_remote = false @allow_cached = false @allow_local = ["allow_local"] || false @prefer_local = false @checksum_store = Checksum::Store.new Array(["remotes"]).reverse_each {|r| add_remote(r) } @lockfile_remotes = @remotes if ["from_lockfile"] end |
Instance Attribute Details
permalink #remotes ⇒ Object
Returns the value of attribute remotes.
13 14 15 |
# File 'lib/bundler/source/rubygems.rb', line 13 def remotes @remotes end |
Class Method Details
permalink .from_lock(options) ⇒ Object
[View source]
103 104 105 106 |
# File 'lib/bundler/source/rubygems.rb', line 103 def self.from_lock() ["remotes"] = Array(.delete("remote")).reverse new(.merge("from_lockfile" => true)) end |
Instance Method Details
permalink #add_remote(source) ⇒ Object
[View source]
254 255 256 257 |
# File 'lib/bundler/source/rubygems.rb', line 254 def add_remote(source) uri = normalize_uri(source) @remotes.unshift(uri) unless @remotes.include?(uri) end |
permalink #cache(spec, custom_path = nil) ⇒ Object
[View source]
229 230 231 232 233 234 235 236 237 238 |
# File 'lib/bundler/source/rubygems.rb', line 229 def cache(spec, custom_path = nil) cached_path = Bundler.settings[:cache_all_platforms] ? fetch_gem_if_possible(spec) : cached_gem(spec) raise GemNotFound, "Missing gem file '#{spec.file_name}'." 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 |
permalink #cached! ⇒ Object
[View source]
63 64 65 66 67 68 69 70 |
# File 'lib/bundler/source/rubygems.rb', line 63 def cached! return unless File.exist?(cache_path) return if @allow_cached @specs = nil @allow_cached = true end |
permalink #cached_built_in_gem(spec, local: false) ⇒ Object
[View source]
240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/bundler/source/rubygems.rb', line 240 def cached_built_in_gem(spec, local: false) cached_path = cached_gem(spec) if cached_path.nil? && !local remote_spec = remote_specs.search(spec).first if remote_spec cached_path = fetch_gem(remote_spec) spec.remote = remote_spec.remote 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 |
permalink #caches ⇒ Object
[View source]
30 31 32 |
# File 'lib/bundler/source/rubygems.rb', line 30 def caches @caches ||= [cache_path, *Bundler.rubygems.gem_cache] end |
permalink #can_lock?(spec) ⇒ Boolean
94 95 96 97 |
# File 'lib/bundler/source/rubygems.rb', line 94 def can_lock?(spec) return super unless multiple_remotes? include?(spec.source) end |
permalink #dependency_api_available? ⇒ Boolean
321 322 323 |
# File 'lib/bundler/source/rubygems.rb', line 321 def dependency_api_available? @allow_remote && api_fetchers.any? end |
permalink #dependency_names_to_double_check ⇒ Object
[View source]
306 307 308 309 310 311 312 313 314 315 316 317 318 319 |
# File 'lib/bundler/source/rubygems.rb', line 306 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.map(&:name)) when RemoteSpecification # from the full index return nil else raise "unhandled spec type (#{spec.inspect})" end end names end |
permalink #double_check_for(unmet_dependency_names) ⇒ Object
[View source]
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
# File 'lib/bundler/source/rubygems.rb', line 286 def double_check_for(unmet_dependency_names) return unless dependency_api_available? 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, remote_specs) specs.use remote_specs end |
permalink #eql?(other) ⇒ Boolean Also known as: ==
76 77 78 |
# File 'lib/bundler/source/rubygems.rb', line 76 def eql?(other) other.is_a?(Rubygems) && other.credless_remotes == credless_remotes end |
permalink #fetchers ⇒ Object
[View source]
282 283 284 |
# File 'lib/bundler/source/rubygems.rb', line 282 def fetchers @fetchers ||= remote_fetchers.values.freeze end |
permalink #hash ⇒ Object
[View source]
72 73 74 |
# File 'lib/bundler/source/rubygems.rb', line 72 def hash @remotes.hash end |
permalink #identifier ⇒ Object Also known as: name, to_gemfile
[View source]
132 133 134 135 136 137 138 |
# File 'lib/bundler/source/rubygems.rb', line 132 def identifier if remotes.empty? "locally installed gems" else "rubygems repository #{remote_names}" end end |
permalink #include?(o) ⇒ Boolean
82 83 84 |
# File 'lib/bundler/source/rubygems.rb', line 82 def include?(o) o.is_a?(Rubygems) && (o.credless_remotes - credless_remotes).empty? end |
permalink #install(spec, options = {}) ⇒ Object
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 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/bundler/source/rubygems.rb', line 165 def install(spec, = {}) if (spec.default_gem? && !cached_built_in_gem(spec, local: [:local])) || (installed?(spec) && ![:force]) "Using #{(spec, [:previous_spec])}" return nil # no post-install message end if spec.remote # Check for this spec from other sources uris = [spec.remote, *remotes_for_spec(spec)].map(&:anonymized_uri).uniq Installer.ambiguous_gems << [spec.name, *uris] if uris.length > 1 end path = fetch_gem_if_possible(spec, [:previous_spec]) raise GemNotFound, "Could not find #{spec.file_name} for installation" unless path return if Bundler.settings[:no_install] install_path = rubygems_dir bin_path = Bundler.system_bindir require_relative "../rubygems_gem_installer" installer = Bundler::RubyGemsGemInstaller.at( path, security_policy: Bundler.rubygems.security_policies[Bundler.settings["trust-policy"]], install_dir: install_path.to_s, bin_dir: bin_path.to_s, ignore_dependencies: true, wrappers: true, env_shebang: true, build_args: [:build_args], bundler_extension_cache_path: extension_cache_path(spec) ) if spec.remote s = begin installer.spec rescue Gem::Package::FormatError Bundler.rm_rf(path) raise rescue Gem::Security::Exception => e raise SecurityError, "The gem #{File.basename(path, ".gem")} can't be installed because " \ "the security policy didn't allow it, with the message: #{e.}" end spec.__swap__(s) end spec.source.checksum_store.register(spec, installer.gem_checksum) = "Installing #{(spec, [:previous_spec])}" += " with native extensions" if spec.extensions.any? Bundler.ui.confirm installed_spec = installer.install spec.full_gem_path = installed_spec.full_gem_path spec.loaded_from = installed_spec.loaded_from spec.base_dir = installed_spec.base_dir spec. end |
permalink #local! ⇒ Object
[View source]
49 50 51 52 53 54 |
# File 'lib/bundler/source/rubygems.rb', line 49 def local! return if @allow_local @specs = nil @allow_local = true end |
permalink #local_only! ⇒ Object
[View source]
38 39 40 41 42 43 |
# File 'lib/bundler/source/rubygems.rb', line 38 def local_only! @specs = nil @allow_local = true @allow_cached = false @allow_remote = false end |
permalink #local_only? ⇒ Boolean
45 46 47 |
# File 'lib/bundler/source/rubygems.rb', line 45 def local_only? @allow_local && !@allow_remote end |
permalink #multiple_remotes? ⇒ Boolean
86 87 88 |
# File 'lib/bundler/source/rubygems.rb', line 86 def multiple_remotes? @remotes.size > 1 end |
permalink #no_remotes? ⇒ Boolean
90 91 92 |
# File 'lib/bundler/source/rubygems.rb', line 90 def no_remotes? @remotes.size == 0 end |
permalink #options ⇒ Object
[View source]
99 100 101 |
# File 'lib/bundler/source/rubygems.rb', line 99 def { "remotes" => @remotes.map(&:to_s) } end |
permalink #prefer_local! ⇒ Object
[View source]
34 35 36 |
# File 'lib/bundler/source/rubygems.rb', line 34 def prefer_local! @prefer_local = true end |
permalink #remote! ⇒ Object
[View source]
56 57 58 59 60 61 |
# File 'lib/bundler/source/rubygems.rb', line 56 def remote! return if @allow_remote @specs = nil @allow_remote = true end |
permalink #remote_fetchers ⇒ Object
[View source]
275 276 277 278 279 280 |
# File 'lib/bundler/source/rubygems.rb', line 275 def remote_fetchers @remote_fetchers ||= remotes.to_h do |uri| remote = Source::Rubygems::Remote.new(uri) [remote, Bundler::Fetcher.new(remote)] end.freeze end |
permalink #spec_names ⇒ Object
[View source]
259 260 261 262 263 264 265 |
# File 'lib/bundler/source/rubygems.rb', line 259 def spec_names if dependency_api_available? remote_specs.spec_names else [] end end |
permalink #specs ⇒ Object
[View source]
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/bundler/source/rubygems.rb', line 142 def specs @specs ||= begin # remote_specs usually generates a way larger Index than the other # sources, and large_idx.merge! small_idx is way faster than # small_idx.merge! large_idx. index = @allow_remote ? remote_specs.dup : Index.new index.merge!(cached_specs) if @allow_cached index.merge!(installed_specs) if @allow_local if @allow_local if @prefer_local index.merge!(default_specs) else # complete with default specs, only if not already available in the # index through remote, cached, or installed specs index.use(default_specs) end end index end end |
permalink #to_lock ⇒ Object
[View source]
108 109 110 111 112 113 114 |
# File 'lib/bundler/source/rubygems.rb', line 108 def to_lock out = String.new("GEM\n") lockfile_remotes.reverse_each do |remote| out << " remote: #{remote}\n" end out << " specs:\n" end |
permalink #to_s ⇒ Object
[View source]
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/bundler/source/rubygems.rb', line 116 def to_s if remotes.empty? "locally installed gems" elsif @allow_remote && @allow_cached && @allow_local "rubygems repository #{remote_names}, cached gems or installed locally" elsif @allow_remote && @allow_local "rubygems repository #{remote_names} or installed locally" elsif @allow_remote "rubygems repository #{remote_names}" elsif @allow_cached && @allow_local "cached gems or installed locally" else "locally installed gems" end end |
permalink #unmet_deps ⇒ Object
[View source]
267 268 269 270 271 272 273 |
# File 'lib/bundler/source/rubygems.rb', line 267 def unmet_deps if dependency_api_available? remote_specs.unmet_dependency_names else [] end end |