Class: Bundler::Source::Rubygems
- Inherits:
-
Object
- Object
- Bundler::Source::Rubygems
- Defined in:
- lib/bundler/source.rb
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.
14 15 16 17 18 19 20 21 22 |
# File 'lib/bundler/source.rb', line 14 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 ] + Gem.path.map { |p| File.("#{p}/cache") } @spec_fetch_map = {} end |
Instance Attribute Details
#remotes ⇒ Object (readonly)
Returns the value of attribute remotes.
12 13 14 |
# File 'lib/bundler/source.rb', line 12 def remotes @remotes end |
Class Method Details
.from_lock(options) ⇒ Object
46 47 48 49 50 |
# File 'lib/bundler/source.rb', line 46 def self.from_lock() s = new() Array(["remote"]).each { |r| s.add_remote(r) } s end |
Instance Method Details
#add_remote(source) ⇒ Object
123 124 125 |
# File 'lib/bundler/source.rb', line 123 def add_remote(source) @remotes << normalize_uri(source) end |
#cache(spec) ⇒ Object
115 116 117 118 119 120 121 |
# File 'lib/bundler/source.rb', line 115 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
28 29 30 |
# File 'lib/bundler/source.rb', line 28 def cached! @allow_cached = true end |
#eql?(o) ⇒ Boolean Also known as: ==
36 37 38 |
# File 'lib/bundler/source.rb', line 36 def eql?(o) Rubygems === o end |
#fetch(spec) ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/bundler/source.rb', line 68 def fetch(spec) spec, uri = @spec_fetch_map[spec.full_name] if spec path = download_gem_from_uri(spec, uri) s = Gem::Format.from_file_by_path(path).spec spec.__swap__(s) end end |
#hash ⇒ Object
32 33 34 |
# File 'lib/bundler/source.rb', line 32 def hash Rubygems.hash end |
#install(spec) ⇒ Object
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 |
# File 'lib/bundler/source.rb', line 77 def install(spec) path = cached_gem(spec) if installed_specs[spec].any? Bundler.ui.info "Using #{spec.name} (#{spec.version}) " return end Bundler.ui.info "Installing #{spec.name} (#{spec.version}) " install_path = Bundler.requires_sudo? ? Bundler.tmp : 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 = Gem::Installer.new path, installer.install # SUDO HAX if Bundler.requires_sudo? sudo "mkdir -p #{Gem.dir}/gems #{Gem.dir}/specifications" sudo "cp -R #{Bundler.tmp}/gems/#{spec.full_name} #{Gem.dir}/gems/" sudo "cp -R #{Bundler.tmp}/specifications/#{spec.full_name}.gemspec #{Gem.dir}/specifications/" spec.executables.each do |exe| sudo "mkdir -p #{Gem.bindir}" sudo "cp -R #{Bundler.tmp}/bin/#{exe} #{Gem.bindir}" end end spec.loaded_from = "#{Gem.dir}/specifications/#{spec.full_name}.gemspec" end |
#merge_remotes(source) ⇒ Object
127 128 129 130 131 132 |
# File 'lib/bundler/source.rb', line 127 def merge_remotes(source) @remotes = [] source.remotes.each do |r| add_remote r.to_s end end |
#options ⇒ Object
42 43 44 |
# File 'lib/bundler/source.rb', line 42 def { "remotes" => @remotes.map { |r| r.to_s } } end |
#remote! ⇒ Object
24 25 26 |
# File 'lib/bundler/source.rb', line 24 def remote! @allow_remote = true end |
#specs ⇒ Object
64 65 66 |
# File 'lib/bundler/source.rb', line 64 def specs @specs ||= fetch_specs end |
#sudo(str) ⇒ Object
111 112 113 |
# File 'lib/bundler/source.rb', line 111 def sudo(str) Bundler.sudo(str) end |
#to_lock ⇒ Object
52 53 54 55 56 |
# File 'lib/bundler/source.rb', line 52 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
58 59 60 61 |
# File 'lib/bundler/source.rb', line 58 def to_s remote_names = self.remotes.map { |r| r.to_s }.join(', ') "rubygems repository #{remote_names}" end |