Class: Bundler::Source::Rubygems
Overview
TODO: Refactor this class
Instance Attribute Summary collapse
-
#remotes ⇒ Object
readonly
Returns the value of attribute remotes.
Class Method Summary collapse
Instance Method Summary collapse
- #add_remote(source) ⇒ Object
- #cache(spec) ⇒ Object
- #cached! ⇒ Object
- #eql?(o) ⇒ Boolean (also: #==)
- #fetch(spec) ⇒ Object
- #hash ⇒ Object
-
#initialize(options = {}) ⇒ Rubygems
constructor
A new instance of Rubygems.
- #install(spec) ⇒ Object
- #merge_remotes(source) ⇒ Object
- #options ⇒ Object
- #remote! ⇒ Object
- #specs ⇒ Object
- #sudo(str) ⇒ Object
- #to_lock ⇒ Object
- #to_s ⇒ Object (also: #name)
Constructor Details
#initialize(options = {}) ⇒ Rubygems
Returns a new instance of Rubygems.
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/bundler/source.rb', line 15 def initialize( = {}) @options = @remotes = (["remotes"] || []).map { |r| normalize_uri(r) } @allow_remote = false @allow_cached = false # Hardcode the paths for now @caches = [ Bundler.app_cache ] + Bundler.rubygems.gem_path.map do |x| File.("#{x}/cache") end @spec_fetch_map = {} end |
Instance Attribute Details
#remotes ⇒ Object (readonly)
Returns the value of attribute remotes.
13 14 15 |
# File 'lib/bundler/source.rb', line 13 def remotes @remotes end |
Class Method Details
.from_lock(options) ⇒ Object
51 52 53 54 55 |
# File 'lib/bundler/source.rb', line 51 def self.from_lock() s = new() Array(["remote"]).each { |r| s.add_remote(r) } s end |
Instance Method Details
#add_remote(source) ⇒ Object
130 131 132 |
# File 'lib/bundler/source.rb', line 130 def add_remote(source) @remotes << normalize_uri(source) end |
#cache(spec) ⇒ Object
122 123 124 125 126 127 128 |
# File 'lib/bundler/source.rb', line 122 def cache(spec) cached_path = cached_gem(spec) 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) end |
#cached! ⇒ Object
33 34 35 |
# File 'lib/bundler/source.rb', line 33 def cached! @allow_cached = true end |
#eql?(o) ⇒ Boolean Also known as: ==
41 42 43 |
# File 'lib/bundler/source.rb', line 41 def eql?(o) Rubygems === o end |
#fetch(spec) ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/bundler/source.rb', line 73 def fetch(spec) spec, uri = @spec_fetch_map[spec.full_name] if spec path = download_gem_from_uri(spec, uri) s = Bundler.rubygems.spec_from_gem(path) spec.__swap__(s) end end |
#install(spec) ⇒ Object
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 |
# File 'lib/bundler/source.rb', line 82 def install(spec) if installed_specs[spec].any? Bundler.ui.info "Using #{spec.name} (#{spec.version}) " return end Bundler.ui.info "Installing #{spec.name} (#{spec.version}) " path = cached_gem(spec) Bundler.rubygems.preserve_paths do install_path = Bundler.requires_sudo? ? Bundler.tmp : Bundler.rubygems.gem_dir = { :install_dir => install_path, :ignore_dependencies => true, :wrappers => true, :env_shebang => true } .merge!(:bin_dir => "#{install_path}/bin") unless spec.executables.nil? || spec.executables.empty? installer = Bundler::GemInstaller.new path, installer.install end # SUDO HAX if Bundler.requires_sudo? sudo "mkdir -p #{Bundler.rubygems.gem_dir}/gems #{Bundler.rubygems.gem_dir}/specifications" sudo "cp -R #{Bundler.tmp}/gems/#{spec.full_name} #{Bundler.rubygems.gem_dir}/gems/" sudo "cp -R #{Bundler.tmp}/specifications/#{spec.full_name}.gemspec #{Bundler.rubygems.gem_dir}/specifications/" spec.executables.each do |exe| sudo "mkdir -p #{Bundler.rubygems.gem_bindir}" sudo "cp -R #{Bundler.tmp}/bin/#{exe} #{Bundler.rubygems.gem_bindir}" end end spec.loaded_from = "#{Bundler.rubygems.gem_dir}/specifications/#{spec.full_name}.gemspec" end |
#merge_remotes(source) ⇒ Object
134 135 136 137 138 139 |
# File 'lib/bundler/source.rb', line 134 def merge_remotes(source) @remotes = [] source.remotes.each do |r| add_remote r.to_s end end |
#options ⇒ Object
47 48 49 |
# File 'lib/bundler/source.rb', line 47 def { "remotes" => @remotes.map { |r| r.to_s } } end |
#remote! ⇒ Object
29 30 31 |
# File 'lib/bundler/source.rb', line 29 def remote! @allow_remote = true end |
#specs ⇒ Object
69 70 71 |
# File 'lib/bundler/source.rb', line 69 def specs @specs ||= fetch_specs end |
#sudo(str) ⇒ Object
118 119 120 |
# File 'lib/bundler/source.rb', line 118 def sudo(str) Bundler.sudo(str) end |
#to_lock ⇒ Object
57 58 59 60 61 |
# File 'lib/bundler/source.rb', line 57 def to_lock out = "GEM\n" out << remotes.map {|r| " remote: #{r}\n" }.join out << " specs:\n" end |
#to_s ⇒ Object Also known as: name
63 64 65 66 |
# File 'lib/bundler/source.rb', line 63 def to_s remote_names = self.remotes.map { |r| r.to_s }.join(', ') "rubygems repository #{remote_names}" end |