Class: Bundler::Bundle

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler08/bundle.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gemfile) ⇒ Bundle

TODO: passing in the filename is not good



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/bundler08/bundle.rb', line 30

def initialize(gemfile)
  @gemfile = gemfile
  @environment = Environment.new(self)
  Dsl.evaluate(gemfile, self, @environment)

  # path   = env.gem_path

  FileUtils.mkdir_p(gem_path)

  @cache_path = gem_path.join('cache')
  @cache = GemDirectorySource.new(self, :location => @cache_path)

  @specs_path = gem_path.join('specifications')
  @gems_path  = gem_path.join('gems')
end

Instance Attribute Details

#environmentObject (readonly)

Returns the value of attribute environment.



5
6
7
# File 'lib/bundler08/bundle.rb', line 5

def environment
  @environment
end

#gemfileObject (readonly)

Returns the value of attribute gemfile.



5
6
7
# File 'lib/bundler08/bundle.rb', line 5

def gemfile
  @gemfile
end

Class Method Details

.default_gemfileObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/bundler08/bundle.rb', line 17

def self.default_gemfile
  current = Pathname.new(Dir.pwd)

  until current.root?
    filename = current.join("Gemfile")
    return filename if filename.exist?
    current = current.parent
  end

  raise DefaultManifestNotFound
end

.load(gemfile = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/bundler08/bundle.rb', line 7

def self.load(gemfile = nil)
  gemfile = Pathname.new(gemfile || default_gemfile).expand_path

  unless gemfile.file?
    raise ManifestFileNotFound, "Manifest file not found: #{gemfile.to_s.inspect}"
  end

  new(gemfile)
end

Instance Method Details

#bindirObject



62
63
64
# File 'lib/bundler08/bundle.rb', line 62

def bindir
  @bindir ||= root.join("bin")
end

#bindir=(path) ⇒ Object



66
67
68
# File 'lib/bundler08/bundle.rb', line 66

def bindir=(path)
  @bindir = (path.relative? ? root.join(path) : path).expand_path
end

#cache(*gemfiles) ⇒ Object



106
107
108
109
110
111
112
# File 'lib/bundler08/bundle.rb', line 106

def cache(*gemfiles)
  FileUtils.mkdir_p(@cache_path)
  gemfiles.each do |gemfile|
    Bundler.logger.info "Caching: #{File.basename(gemfile)}"
    FileUtils.cp(gemfile, @cache_path)
  end
end

#download_path_for(type) ⇒ Object



159
160
161
# File 'lib/bundler08/bundle.rb', line 159

def download_path_for(type)
  @repos[type].download_path_for
end

#gem_pathObject



58
59
60
# File 'lib/bundler08/bundle.rb', line 58

def gem_path
  path.join("#{Gem.ruby_engine}/#{Gem::ConfigMap[:ruby_version]}")
end

#gemsObject



149
150
151
# File 'lib/bundler08/bundle.rb', line 149

def gems
  source_index.gems.values
end

#install(options = {}) ⇒ Object



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
# File 'lib/bundler08/bundle.rb', line 70

def install(options = {})
  dependencies = @environment.dependencies
  sources      = @environment.sources

  # ========== from env
  if only_envs = options[:only]
    dependencies.reject! { |d| !only_envs.any? {|env| d.in?(env) } }
  end
  # ==========

  # Check to see whether the existing cache meets all the requirements
  begin
    valid = nil
    # valid = Resolver.resolve(dependencies, [source_index], source_requirements)
  rescue Bundler::GemNotFound
  end

  sources = only_local(sources) if options[:cached]

  # Check the remote sources if the existing cache does not meet the requirements
  # or the user passed --update
  if options[:update] || !valid
    Bundler.logger.info "Calculating dependencies..."
    bundle = Resolver.resolve(dependencies, [@cache] + sources)
    download(bundle, options)
    do_install(bundle, options)
    valid = bundle
  end

  generate_bins(valid, options)
  cleanup(valid, options)
  configure(valid, options)

  Bundler.logger.info "Done."
end

#list(options = {}) ⇒ Object



142
143
144
145
146
147
# File 'lib/bundler08/bundle.rb', line 142

def list(options = {})
  Bundler.logger.info "Currently bundled gems:"
  gems.each do |spec|
    Bundler.logger.info " * #{spec.name} (#{spec.version})"
  end
end

#list_outdated(options = {}) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/bundler08/bundle.rb', line 114

def list_outdated(options={})
  outdated_gems = source_index.outdated.sort

  if outdated_gems.empty?
    Bundler.logger.info "All gems are up to date."
  else
    Bundler.logger.info "Outdated gems:"
    outdated_gems.each do |name|
      Bundler.logger.info " * #{name}"
    end
  end
end

#pathObject



50
51
52
# File 'lib/bundler08/bundle.rb', line 50

def path
  @path ||= root.join("vendor/gems")
end

#path=(path) ⇒ Object



54
55
56
# File 'lib/bundler08/bundle.rb', line 54

def path=(path)
  @path = (path.relative? ? root.join(path) : path).expand_path
end

#prune(options = {}) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/bundler08/bundle.rb', line 127

def prune(options = {})
  dependencies, sources = @environment.dependencies, @environment.sources

  sources = only_local(sources)
  bundle = Resolver.resolve(dependencies, [@cache] + sources)
  @cache.gems.each do |name, specs|
    specs.each do |spec|
      unless bundle.any? { |s| s.name == spec.name && s.version == spec.version }
        Bundler.logger.info "Pruning #{spec.name} (#{spec.version}) from the cache"
        FileUtils.rm @cache_path.join("#{spec.full_name}.gem")
      end
    end
  end
end

#rootObject



46
47
48
# File 'lib/bundler08/bundle.rb', line 46

def root
  gemfile.parent
end

#setup_environmentObject



163
164
165
166
167
168
169
170
# File 'lib/bundler08/bundle.rb', line 163

def setup_environment
  unless @environment.system_gems
    ENV["GEM_HOME"] = gem_path
    ENV["GEM_PATH"] = gem_path
  end
  ENV["PATH"]     = "#{bindir}:#{ENV["PATH"]}"
  ENV["RUBYOPT"]  = "-r#{gem_path}/environment #{ENV["RUBYOPT"]}"
end

#source_indexObject



153
154
155
156
157
# File 'lib/bundler08/bundle.rb', line 153

def source_index
  index = Gem::SourceIndex.from_gems_in(@specs_path)
  index.each { |n, spec| spec.loaded_from = @specs_path.join("#{spec.full_name}.gemspec") }
  index
end