Included Modules

Class Index [+]

Quicksearch

Bundler::Runtime

Constants

REGEXPS

Public Instance Methods

cache() click to toggle source
     # File lib/bundler/runtime.rb, line 97
 97:     def cache
 98:       FileUtils.mkdir_p(cache_path) unless File.exists?(cache_path)
 99: 
100:       Bundler.ui.info "Updating .gem files in vendor/cache"
101:       specs.each do |spec|
102:         next if spec.name == 'bundler'
103:         spec.source.cache(spec) if spec.source.respond_to?(:cache)
104:       end
105:       prune_cache unless Bundler.settings[:no_prune]
106:     end
clean() click to toggle source
     # File lib/bundler/runtime.rb, line 132
132:     def clean
133:       gem_bins             = Dir["#{Gem.dir}/bin/*"]
134:       git_dirs             = Dir["#{Gem.dir}/bundler/gems/*"]
135:       git_cache_dirs       = Dir["#{Gem.dir}/cache/bundler/git/*"]
136:       gem_dirs             = Dir["#{Gem.dir}/gems/*"]
137:       gem_files            = Dir["#{Gem.dir}/cache/*.gem"]
138:       gemspec_files        = Dir["#{Gem.dir}/specifications/*.gemspec"]
139:       spec_gem_paths       = []
140:       spec_git_paths       = []
141:       spec_git_cache_dirs  = []
142:       spec_gem_executables = []
143:       spec_cache_paths     = []
144:       spec_gemspec_paths   = []
145:       specs.each do |spec|
146:         spec_gem_paths << spec.full_gem_path
147:         # need to check here in case gems are nested like for the rails git repo
148:         md = %{(.+bundler/gems/.+-[a-f0-9]{7,12})}.match(spec.full_gem_path)
149:         spec_git_paths << md[1] if md
150:         spec_gem_executables << spec.executables.collect do |executable|
151:           "#{Bundler.rubygems.gem_bindir}/#{executable}"
152:         end
153:         spec_cache_paths << spec.cache_file
154:         spec_gemspec_paths << spec.spec_file
155:         spec_git_cache_dirs << spec.source.cache_path.to_s if spec.source.is_a?(Bundler::Source::Git)
156:       end
157:       spec_gem_paths.uniq!
158:       spec_gem_executables.flatten!
159: 
160:       stale_gem_bins       = gem_bins - spec_gem_executables
161:       stale_git_dirs       = git_dirs - spec_git_paths
162:       stale_git_cache_dirs = git_cache_dirs - spec_git_cache_dirs
163:       stale_gem_dirs       = gem_dirs - spec_gem_paths
164:       stale_gem_files      = gem_files - spec_cache_paths
165:       stale_gemspec_files  = gemspec_files - spec_gemspec_paths
166: 
167:       stale_gem_bins.each {|bin| FileUtils.rm(bin) }
168:       output = stale_gem_dirs.collect do |gem_dir|
169:         full_name = Pathname.new(gem_dir).basename.to_s
170: 
171:         FileUtils.rm_rf(gem_dir)
172: 
173:         parts   = full_name.split('-')
174:         name    = parts[0..2].join('-')
175:         version = parts.last
176:         output  = "#{name} (#{version})"
177: 
178:         Bundler.ui.info "Removing #{output}"
179: 
180:         output
181:       end + stale_git_dirs.collect do |gem_dir|
182:         full_name = Pathname.new(gem_dir).basename.to_s
183: 
184:         FileUtils.rm_rf(gem_dir)
185: 
186:         parts    = full_name.split('-')
187:         name     = parts[0..2].join('-')
188:         revision = parts[1]
189:         output   = "#{name} (#{revision})"
190: 
191:         Bundler.ui.info "Removing #{output}"
192: 
193:         output
194:       end
195: 
196:       stale_gem_files.each {|file| FileUtils.rm(file) if File.exists?(file) }
197:       stale_gemspec_files.each {|file| FileUtils.rm(file) if File.exists?(file) }
198:       stale_git_cache_dirs.each {|dir| FileUtils.rm_rf(dir) if File.exists?(dir) }
199: 
200:       output
201:     end
dependencies_for(*groups) click to toggle source
    # File lib/bundler/runtime.rb, line 87
87:     def dependencies_for(*groups)
88:       if groups.empty?
89:         dependencies
90:       else
91:         dependencies.select { |d| (groups & d.groups).any? }
92:       end
93:     end
prune_cache() click to toggle source
     # File lib/bundler/runtime.rb, line 108
108:     def prune_cache
109:       FileUtils.mkdir_p(cache_path) unless File.exists?(cache_path)
110: 
111:       resolve = @definition.resolve
112:       cached  = Dir["#{cache_path}/*.gem"]
113: 
114:       cached = cached.delete_if do |path|
115:         spec = Bundler.rubygems.spec_from_gem path
116: 
117:         resolve.any? do |s|
118:           s.name == spec.name && s.version == spec.version && !s.source.is_a?(Bundler::Source::Git)
119:         end
120:       end
121: 
122:       if cached.any?
123:         Bundler.ui.info "Removing outdated .gem files from vendor/cache"
124: 
125:         cached.each do |path|
126:           Bundler.ui.info "  * #{File.basename(path)}"
127:           File.delete(path)
128:         end
129:       end
130:     end
require(*groups) click to toggle source
    # File lib/bundler/runtime.rb, line 51
51:     def require(*groups)
52:       groups.map! { |g| g.to_sym }
53:       groups = [:default] if groups.empty?
54: 
55:       @definition.dependencies.each do |dep|
56:         # Skip the dependency if it is not in any of the requested
57:         # groups
58:         next unless ((dep.groups & groups).any? && dep.current_platform?)
59: 
60:         required_file = nil
61: 
62:         begin
63:           # Loop through all the specified autorequires for the
64:           # dependency. If there are none, use the dependency's name
65:           # as the autorequire.
66:           Array(dep.autorequire || dep.name).each do |file|
67:             required_file = file
68:             Kernel.require file
69:           end
70:         rescue LoadError => e
71:           if dep.autorequire.nil? && dep.name.include?('-')
72:             begin
73:               namespaced_file = dep.name.gsub('-', '/')
74:               Kernel.require namespaced_file
75:             rescue LoadError
76:               REGEXPS.find { |r| r =~ e.message }
77:               raise if dep.autorequire || $1.gsub('-', '/') != namespaced_file
78:             end
79:           else
80:             REGEXPS.find { |r| r =~ e.message }
81:             raise if dep.autorequire || $1 != required_file
82:           end
83:         end
84:       end
85:     end
setup(*groups) click to toggle source
    # File lib/bundler/runtime.rb, line 7
 7:     def setup(*groups)
 8:       # Has to happen first
 9:       clean_load_path
10: 
11:       specs = groups.any? ? @definition.specs_for(groups) : requested_specs
12: 
13:       setup_environment
14:       Bundler.rubygems.replace_entrypoints(specs)
15: 
16:       # Activate the specs
17:       specs.each do |spec|
18:         unless spec.loaded_from
19:           raise GemNotFound, "#{spec.full_name} is missing. Run `bundle` to get it."
20:         end
21: 
22:         if activated_spec = Bundler.rubygems.loaded_specs(spec.name) and activated_spec.version != spec.version
23:           e = Gem::LoadError.new "You have already activated #{activated_spec.name} #{activated_spec.version}, "                                   "but your Gemfile requires #{spec.name} #{spec.version}. Using bundle exec may solve this."
24:           e.name = spec.name
25:           if e.respond_to?(:requirement=)
26:             e.requirement = Gem::Requirement.new(spec.version.to_s)
27:           else
28:             e.version_requirement = Gem::Requirement.new(spec.version.to_s)
29:           end
30:           raise e
31:         end
32: 
33:         Bundler.rubygems.mark_loaded(spec)
34:         load_paths = spec.load_paths.reject {|path| $LOAD_PATH.include?(path)}
35:         $LOAD_PATH.unshift(*load_paths)
36:       end
37: 
38:       lock
39: 
40:       self
41:     end
setup_environment() click to toggle source
     # File lib/bundler/runtime.rb, line 203
203:     def setup_environment
204:       begin
205:         ENV["BUNDLE_BIN_PATH"] = Bundler.rubygems.bin_path("bundler", "bundle", VERSION)
206:       rescue Gem::GemNotFoundException
207:         ENV["BUNDLE_BIN_PATH"] = File.expand_path("../../../bin/bundle", __FILE__)
208:       end
209: 
210:       # Set PATH
211:       paths = (ENV["PATH"] || "").split(File::PATH_SEPARATOR)
212:       paths.unshift "#{Bundler.bundle_path}/bin"
213:       ENV["PATH"] = paths.uniq.join(File::PATH_SEPARATOR)
214: 
215:       # Set BUNDLE_GEMFILE
216:       ENV["BUNDLE_GEMFILE"] = default_gemfile.to_s
217: 
218:       # Set RUBYOPT
219:       rubyopt = [ENV["RUBYOPT"]].compact
220:       if rubyopt.empty? || rubyopt.first !~ /-rbundler\/setup/
221:         rubyopt.unshift "-rbundler/setup"
222:         rubyopt.unshift "-I#{File.expand_path('../..', __FILE__)}"
223:         ENV["RUBYOPT"] = rubyopt.join(' ')
224:       end
225:     end

Private Instance Methods

cache_path() click to toggle source
     # File lib/bundler/runtime.rb, line 229
229:     def cache_path
230:       root.join("vendor/cache")
231:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.