Class: Bundler::Source::Rubygems

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler/source.rb

Overview

TODO: Refactor this class

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Rubygems

Returns a new instance of Rubygems.



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

def initialize(options = {})
  @options = options
  @remotes = (options["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.expand_path("#{p}/cache") }
  @spec_fetch_map = {}
end

Instance Attribute Details

#remotesObject (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



47
48
49
50
51
# File 'lib/bundler/source.rb', line 47

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

Instance Method Details

#add_remote(source) ⇒ Object



124
125
126
# File 'lib/bundler/source.rb', line 124

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

#cache(spec) ⇒ Object

Raises:



116
117
118
119
120
121
122
# File 'lib/bundler/source.rb', line 116

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



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

def cached!
  @allow_cached = true
end

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

Returns:

  • (Boolean)


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

def eql?(o)
  Rubygems === o
end

#fetch(spec) ⇒ Object



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

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

#hashObject



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

def hash
  Rubygems.hash
end

#install(spec) ⇒ Object



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
# File 'lib/bundler/source.rb', line 78

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
  options = { :install_dir         => install_path,
              :ignore_dependencies => true,
              :wrappers            => true,
              :env_shebang         => true }
  options.merge!(:bin_dir => "#{install_path}/bin") unless spec.executables.nil? || spec.executables.empty?

  installer = Gem::Installer.new path, options
  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



128
129
130
131
132
133
# File 'lib/bundler/source.rb', line 128

def merge_remotes(source)
  @remotes = []
  source.remotes.each do |r|
    add_remote r.to_s
  end
end

#optionsObject



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

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

#remote!Object



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

def remote!
  @allow_remote = true
end

#specsObject



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

def specs
  @specs ||= fetch_specs
end

#sudo(str) ⇒ Object



112
113
114
# File 'lib/bundler/source.rb', line 112

def sudo(str)
  Bundler.sudo(str)
end

#to_lockObject



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

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

#to_sObject Also known as: name



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

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