Class: Bundler::Source::Rubygems

Inherits:
Bundler::Source show all
Defined in:
lib/bundler/source/rubygems.rb

Constant Summary collapse

API_REQUEST_LIMIT =

threshold for switching back to the modern index instead of fetching every spec

100
S3_SCHEME =
's3'

Instance Attribute Summary collapse

Attributes inherited from Bundler::Source

#dependency_names

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Bundler::Source

mirror_for, #version_message

Constructor Details

#initialize(options = {}) ⇒ Rubygems

Returns a new instance of Rubygems.


13
14
15
16
17
18
19
20
21
22
# File 'lib/bundler/source/rubygems.rb', line 13

def initialize(options = {})
  @options = options
  @remotes = []
  @dependency_names = []
  @allow_remote = false
  @allow_cached = false
  @caches = [Bundler.app_cache, *Bundler.rubygems.gem_cache]

  Array(options["remotes"] || []).reverse_each{|r| add_remote(r) }
end

Instance Attribute Details

#cachesObject (readonly)

Returns the value of attribute caches


11
12
13
# File 'lib/bundler/source/rubygems.rb', line 11

def caches
  @caches
end

#remotesObject (readonly)

Returns the value of attribute remotes


11
12
13
# File 'lib/bundler/source/rubygems.rb', line 11

def remotes
  @remotes
end

Class Method Details

.from_lock(options) ⇒ Object


50
51
52
# File 'lib/bundler/source/rubygems.rb', line 50

def self.from_lock(options)
  new(options)
end

Instance Method Details

#add_remote(source) ⇒ Object


168
169
170
171
# File 'lib/bundler/source/rubygems.rb', line 168

def add_remote(source)
  uri = normalize_uri(source)
  @remotes.unshift(uri) unless @remotes.include?(uri)
end

#cache(spec, custom_path = nil) ⇒ Object

Raises:


147
148
149
150
151
152
153
154
155
156
157
# File 'lib/bundler/source/rubygems.rb', line 147

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))
end

#cached!Object


28
29
30
# File 'lib/bundler/source/rubygems.rb', line 28

def cached!
  @allow_cached = true
end

#cached_built_in_gem(spec) ⇒ Object


159
160
161
162
163
164
165
166
# File 'lib/bundler/source/rubygems.rb', line 159

def cached_built_in_gem(spec)
  cached_path = cached_path(spec)
  if cached_path.nil?
    remote_spec = remote_specs.search(spec).first
    cached_path = fetch_gem(remote_spec)
  end
  cached_path
end

#can_lock?(spec) ⇒ Boolean

Returns:

  • (Boolean)

42
43
44
# File 'lib/bundler/source/rubygems.rb', line 42

def can_lock?(spec)
  spec.source.is_a?(Rubygems)
end

#eql?(o) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)

36
37
38
# File 'lib/bundler/source/rubygems.rb', line 36

def eql?(o)
  o.is_a?(Rubygems) && remotes_equal?(o.remotes)
end

#fetchersObject


190
191
192
193
194
195
196
197
198
199
# File 'lib/bundler/source/rubygems.rb', line 190

def fetchers
  @fetchers ||= remotes.map do |uri|
    case uri.scheme
    when S3_SCHEME
      Bundler::S3Fetcher.new(uri)
    else
      Bundler::Fetcher.new(uri)
    end
  end
end

#hashObject


32
33
34
# File 'lib/bundler/source/rubygems.rb', line 32

def hash
  @remotes.hash
end

#install(spec) ⇒ Object


80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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
# File 'lib/bundler/source/rubygems.rb', line 80

def install(spec)
  return ["Using #{version_message(spec)}", nil] if installed_specs[spec].any?

  # Download the gem to get the spec, because some specs that are returned
  # by rubygems.org are broken and wrong.
  if spec.source_uri
    # Check for this spec from other sources
    uris = [spec.source_uri.without_credentials]
    uris += source_uris_for_spec(spec)
    uris.uniq!
    Installer.ambiguous_gems << [spec.name, *uris] if uris.length > 1

    s = Bundler.rubygems.spec_from_gem(fetch_gem(spec), Bundler.settings["trust-policy"])
    spec.__swap__(s)
  end

  unless Bundler.settings[:no_install]
    path = cached_gem(spec)
    if Bundler.requires_sudo?
      install_path = Bundler.tmp(spec.full_name)
      bin_path     = install_path.join("bin")
    else
      install_path = Bundler.rubygems.gem_dir
      bin_path     = Bundler.system_bindir
    end

    installed_spec = nil
    Bundler.rubygems.preserve_paths do
      installed_spec = Bundler::GemInstaller.new(path,
        :install_dir         => install_path.to_s,
        :bin_dir             => bin_path.to_s,
        :ignore_dependencies => true,
        :wrappers            => true,
        :env_shebang         => true
      ).install
    end

    # SUDO HAX
    if Bundler.requires_sudo?
      Bundler.rubygems.repository_subdirectories.each do |name|
        src = File.join(install_path, name, "*")
        dst = File.join(Bundler.rubygems.gem_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
        Bundler.mkdir_p dst
        Bundler.sudo "cp -R #{src} #{dst}" if Dir[src].any?
      end

      spec.executables.each do |exe|
        Bundler.mkdir_p Bundler.system_bindir
        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)
  ["Installing #{version_message(spec)}", spec.post_install_message]
ensure
  if install_path && Bundler.requires_sudo?
    FileUtils.remove_entry_secure(install_path)
  end
end

#optionsObject


46
47
48
# File 'lib/bundler/source/rubygems.rb', line 46

def options
  { "remotes" => @remotes.map { |r| r.to_s } }
end

#remote!Object


24
25
26
# File 'lib/bundler/source/rubygems.rb', line 24

def remote!
  @allow_remote = true
end

#replace_remotes(other_remotes) ⇒ Object


173
174
175
176
177
178
179
180
# File 'lib/bundler/source/rubygems.rb', line 173

def replace_remotes(other_remotes)
  return false if other_remotes == @remotes

  @remotes = []
  other_remotes.reverse_each do |r|
    add_remote r.to_s
  end
end

#specsObject


68
69
70
71
72
73
74
75
76
77
78
# File 'lib/bundler/source/rubygems.rb', line 68

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_lockObject


54
55
56
57
58
59
60
# File 'lib/bundler/source/rubygems.rb', line 54

def to_lock
  out = "GEM\n"
  remotes.reverse_each do |remote|
    out << "  remote: #{suppress_configured_credentials remote}\n"
  end
  out << "  specs:\n"
end

#to_sObject Also known as: name


62
63
64
65
# File 'lib/bundler/source/rubygems.rb', line 62

def to_s
  remote_names = self.remotes.map { |r| r.to_s }.join(', ')
  "rubygems repository #{remote_names}"
end

#unmet_depsObject


182
183
184
185
186
187
188
# File 'lib/bundler/source/rubygems.rb', line 182

def unmet_deps
  if @allow_remote && api_fetchers.any?
    remote_specs.unmet_dependency_names
  else
    []
  end
end