Class: Bundler::Source::Rubygems

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

Constant Summary

API_REQUEST_LIMIT =

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

100

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Bundler::Source

mirror_for, #version_message

Constructor Details

- (Rubygems) initialize(options = {})

Returns a new instance of Rubygems



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

def initialize(options = {})
  @options = options
  @remotes = (options["remotes"] || []).map { |r| normalize_uri(r) }
  @fetchers = {}
  @dependency_names = []
  @allow_remote = false
  @allow_cached = false
  @caches = [Bundler.app_cache, *Bundler.rubygems.gem_cache]
end

Instance Attribute Details

- (Object) caches (readonly)

Returns the value of attribute caches



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

def caches
  @caches
end

- (Object) dependency_names

Returns the value of attribute dependency_names



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

def dependency_names
  @dependency_names
end

- (Object) remotes (readonly)

Returns the value of attribute remotes



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

def remotes
  @remotes
end

Class Method Details

+ (Object) from_lock(options)



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

def self.from_lock(options)
  s = new(options)
  Array(options["remote"]).each { |r| s.add_remote(r) }
  s
end

Instance Method Details

- (Object) add_remote(source)



150
151
152
# File 'lib/bundler/source/rubygems.rb', line 150

def add_remote(source)
  @remotes << normalize_uri(source)
end

- (Object) cache(spec, custom_path = nil)

Raises:



129
130
131
132
133
134
135
136
137
138
139
# File 'lib/bundler/source/rubygems.rb', line 129

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

- (Object) cached!



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

def cached!
  @allow_cached = true
end

- (Object) cached_built_in_gem(spec)



141
142
143
144
145
146
147
148
# File 'lib/bundler/source/rubygems.rb', line 141

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

- (Boolean) eql?(o) Also known as: ==

Returns:

  • (Boolean)


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

def eql?(o)
  o.is_a?(Rubygems)
end

- (Object) hash



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

def hash
  Rubygems.hash
end

- (Object) install(spec)



69
70
71
72
73
74
75
76
77
78
79
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
# File 'lib/bundler/source/rubygems.rb', line 69

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
    s = Bundler.rubygems.spec_from_gem(fetch_gem(spec), Bundler.settings["trust-policy"])
    spec.__swap__(s)
  end

  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

  spec.loaded_from = "#{Bundler.rubygems.gem_dir}/specifications/#{spec.full_name}.gemspec"
  installed_spec.loaded_from = spec.loaded_from
  ["Installing #{version_message(spec)}", spec.post_install_message]
ensure
  if install_path && Bundler.requires_sudo?
    FileUtils.remove_entry_secure(install_path)
  end
end

- (Object) options



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

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

- (Object) remote!



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

def remote!
  @allow_remote = true
end

- (Object) replace_remotes(source)



154
155
156
157
158
159
160
161
162
163
# File 'lib/bundler/source/rubygems.rb', line 154

def replace_remotes(source)
  return false if source.remotes == @remotes

  @remotes = []
  source.remotes.each do |r|
    add_remote r.to_s
  end

  true
end

- (Object) specs



65
66
67
# File 'lib/bundler/source/rubygems.rb', line 65

def specs
  @specs ||= fetch_specs
end

- (Object) to_lock



51
52
53
54
55
56
57
# File 'lib/bundler/source/rubygems.rb', line 51

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

- (Object) to_s Also known as: name



59
60
61
62
# File 'lib/bundler/source/rubygems.rb', line 59

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