Parent

Bundler::Source::Rubygems

TODO: Refactor this class

Attributes

remotes[R]

Public Class Methods

from_lock(options) click to toggle source
    # File lib/bundler/source.rb, line 52
52:       def self.from_lock(options)
53:         s = new(options)
54:         Array(options["remote"]).each { |r| s.add_remote(r) }
55:         s
56:       end
new(options = {}) click to toggle source
    # File lib/bundler/source.rb, line 14
14:       def initialize(options = {})
15:         @options = options
16:         @remotes = (options["remotes"] || []).map { |r| normalize_uri(r) }
17:         @allow_remote = false
18:         @allow_cached = false
19:         # Hardcode the paths for now
20:         @caches = [ Bundler.app_cache ] + Gem.path.map { |p| File.expand_path("#{p}/cache") }
21:         @spec_fetch_map = {}
22:       end

Public Instance Methods

==(o) click to toggle source
Alias for: eql?
add_remote(source) click to toggle source
     # File lib/bundler/source.rb, line 128
128:       def add_remote(source)
129:         @remotes << normalize_uri(source)
130:       end
cache(spec) click to toggle source
     # File lib/bundler/source.rb, line 120
120:       def cache(spec)
121:         cached_path = cached_gem(spec)
122:         raise GemNotFound, "Missing gem file '#{spec.full_name}.gem'." unless cached_path
123:         return if File.dirname(cached_path) == Bundler.app_cache.to_s
124:         Bundler.ui.info "  * #{File.basename(cached_path)}"
125:         FileUtils.cp(cached_path, Bundler.app_cache)
126:       end
cached!() click to toggle source
    # File lib/bundler/source.rb, line 28
28:       def cached!
29:         @allow_cached = true
30:       end
eql?(o) click to toggle source
    # File lib/bundler/source.rb, line 36
36:       def eql?(o)
37:         Rubygems === o
38:       end
Also aliased as: ==
fetch(spec) click to toggle source
    # 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 = Gem::Format.from_file_by_path(path).spec
78:           spec.__swap__(s)
79:         end
80:       end
hash() click to toggle source
    # File lib/bundler/source.rb, line 32
32:       def hash
33:         Rubygems.hash
34:       end
install(spec) click to toggle source
     # File lib/bundler/source.rb, line 82
 82:       def install(spec)
 83:         path = cached_gem(spec)
 84: 
 85:         if installed_specs[spec].any?
 86:           Bundler.ui.info "Using #{spec.name} (#{spec.version}) "
 87:           return
 88:         end
 89: 
 90:         Bundler.ui.info "Installing #{spec.name} (#{spec.version}) "
 91: 
 92:         install_path = Bundler.requires_sudo? ? Bundler.tmp : Gem.dir
 93:         options = { :install_dir         => install_path,
 94:                     :ignore_dependencies => true,
 95:                     :wrappers            => true,
 96:                     :env_shebang         => true }
 97:         options.merge!(:bin_dir => "#{install_path}/bin") unless spec.executables.nil? || spec.executables.empty?
 98: 
 99:         installer = Gem::Installer.new path, options
100:         installer.install
101: 
102:         # SUDO HAX
103:         if Bundler.requires_sudo?
104:           sudo "mkdir -p #{Gem.dir}/gems #{Gem.dir}/specifications"
105:           sudo "cp -R #{Bundler.tmp}/gems/#{spec.full_name} #{Gem.dir}/gems/"
106:           sudo "cp -R #{Bundler.tmp}/specifications/#{spec.full_name}.gemspec #{Gem.dir}/specifications/"
107:           spec.executables.each do |exe|
108:             sudo "mkdir -p #{Gem.bindir}"
109:             sudo "cp -R #{Bundler.tmp}/bin/#{exe} #{Gem.bindir}"
110:           end
111:         end
112: 
113:         spec.loaded_from = "#{Gem.dir}/specifications/#{spec.full_name}.gemspec"
114:       end
merge_remotes(source) click to toggle source
     # File lib/bundler/source.rb, line 132
132:       def merge_remotes(source)
133:         @remotes = []
134:         source.remotes.each do |r|
135:           add_remote r.to_s
136:         end
137:       end
name() click to toggle source

Not really needed, but it seems good to implement this method for interface consistency. Source name is mostly used to identify Path & Git sources

    # File lib/bundler/source.rb, line 44
44:       def name
45:         ":gems"
46:       end
options() click to toggle source
    # File lib/bundler/source.rb, line 48
48:       def options
49:         { "remotes" => @remotes.map { |r| r.to_s } }
50:       end
remote!() click to toggle source
    # File lib/bundler/source.rb, line 24
24:       def remote!
25:         @allow_remote = true
26:       end
specs() click to toggle source
    # File lib/bundler/source.rb, line 69
69:       def specs
70:         @specs ||= fetch_specs
71:       end
sudo(str) click to toggle source
     # File lib/bundler/source.rb, line 116
116:       def sudo(str)
117:         Bundler.sudo(str)
118:       end
to_lock() click to toggle source
    # File lib/bundler/source.rb, line 58
58:       def to_lock
59:         out = "GEM\n"
60:         out << remotes.map {|r| "  remote: #{r}\n" }.join
61:         out << "  specs:\n"
62:       end
to_s() click to toggle source
    # File lib/bundler/source.rb, line 64
64:       def to_s
65:         remotes = self.remotes.map { |r| r.to_s }.join(', ')
66:         "rubygems repository #{remotes}"
67:       end

Private Instance Methods

cached_gem(spec) click to toggle source
     # File lib/bundler/source.rb, line 141
141:       def cached_gem(spec)
142:         possibilities = @caches.map { |p| "#{p}/#{spec.full_name}.gem" }
143:         possibilities.find { |p| File.exist?(p) }
144:       end
cached_specs() click to toggle source
     # File lib/bundler/source.rb, line 192
192:       def cached_specs
193:         @cached_specs ||= begin
194:           idx = Index.new
195:           @caches.each do |path|
196:             Dir["#{path}/*.gem"].each do |gemfile|
197:               next if name == 'bundler'
198:               s = Gem::Format.from_file_by_path(gemfile).spec
199:               s.source = self
200:               idx << s
201:             end
202:           end
203:           idx
204:         end
205:       end
download_gem_from_uri(spec, uri) click to toggle source
     # File lib/bundler/source.rb, line 246
246:       def download_gem_from_uri(spec, uri)
247:         spec.fetch_platform
248: 
249:         download_path = Bundler.requires_sudo? ? Bundler.tmp : Gem.dir
250:         gem_path = "#{Gem.dir}/cache/#{spec.full_name}.gem"
251: 
252:         FileUtils.mkdir_p("#{download_path}/cache")
253:         Gem::RemoteFetcher.fetcher.download(spec, uri, download_path)
254: 
255:         if Bundler.requires_sudo?
256:           sudo "mkdir -p #{Gem.dir}/cache"
257:           sudo "mv #{Bundler.tmp}/cache/#{spec.full_name}.gem #{gem_path}"
258:         end
259: 
260:         gem_path
261:       end
fetch_all_remote_specs(&blk) click to toggle source
     # File lib/bundler/source.rb, line 231
231:       def fetch_all_remote_specs(&blk)
232:         begin
233:           # Fetch all specs, minus prerelease specs
234:           Gem::SpecFetcher.new.list(true, false).each(&blk)
235:           # Then fetch the prerelease specs
236:           begin
237:             Gem::SpecFetcher.new.list(false, true).each(&blk)
238:           rescue Gem::RemoteFetcher::FetchError
239:             Bundler.ui.warn "Could not fetch prerelease specs from #{self}"
240:           end
241:         rescue Gem::RemoteFetcher::FetchError
242:           Bundler.ui.warn "Could not reach #{self}"
243:         end
244:       end
fetch_specs() click to toggle source
     # File lib/bundler/source.rb, line 154
154:       def fetch_specs
155:         Index.build do |idx|
156:           idx.use installed_specs
157:           idx.use cached_specs if @allow_cached || @allow_remote
158:           idx.use remote_specs if @allow_remote
159:         end
160:       end
installed_specs() click to toggle source
     # File lib/bundler/source.rb, line 162
162:       def installed_specs
163:         @installed_specs ||= begin
164:           idx = Index.new
165:           have_bundler = false
166:           Gem::SourceIndex.from_installed_gems.to_a.reverse.each do |dont_use_this_var, spec|
167:             next if spec.name == 'bundler' && spec.version.to_s != VERSION
168:             have_bundler = true if spec.name == 'bundler'
169:             spec.source = self
170:             idx << spec
171:           end
172: 
173:           # Always have bundler locally
174:           unless have_bundler
175:            # We're running bundler directly from the source
176:            # so, let's create a fake gemspec for it (it's a path)
177:            # gemspec
178:            bundler = Gem::Specification.new do |s|
179:              s.name     = 'bundler'
180:              s.version  = VERSION
181:              s.platform = Gem::Platform::RUBY
182:              s.source   = self
183:              # TODO: Remove this
184:              s.loaded_from = 'w0t'
185:            end
186:            idx << bundler
187:           end
188:           idx
189:         end
190:       end
normalize_uri(uri) click to toggle source
     # File lib/bundler/source.rb, line 146
146:       def normalize_uri(uri)
147:         uri = uri.to_s
148:         uri = "#{uri}/" unless uri =~ %/$'
149:         uri = URI(uri)
150:         raise ArgumentError, "The source must be an absolute URI" unless uri.absolute?
151:         uri
152:       end
remote_specs() click to toggle source
     # File lib/bundler/source.rb, line 207
207:       def remote_specs
208:         @remote_specs ||= begin
209:           idx     = Index.new
210:           old     = Gem.sources
211: 
212:           remotes.each do |uri|
213:             Bundler.ui.info "Fetching source index for #{uri}"
214:             Gem.sources = ["#{uri}"]
215:             fetch_all_remote_specs do |n,v|
216:               v.each do |name, version, platform|
217:                 next if name == 'bundler'
218:                 spec = RemoteSpecification.new(name, version, platform, uri)
219:                 spec.source = self
220:                 @spec_fetch_map[spec.full_name] = [spec, uri]
221:                 idx << spec
222:               end
223:             end
224:           end
225:           idx
226:         ensure
227:           Gem.sources = old
228:         end
229:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.