module Bundler::SharedHelpers
Attributes
gem_loaded[RW]
Public Instance Methods
chdir(dir, &blk)
click to toggle source
# File lib/bundler/shared_helpers.rb, line 51 def chdir(dir, &blk) Bundler.rubygems.ext_lock.synchronize do Dir.chdir dir, &blk end end
default_bundle_dir()
click to toggle source
# File lib/bundler/shared_helpers.rb, line 37 def default_bundle_dir bundle_dir = find_directory(".bundle") return nil unless bundle_dir global_bundle_dir = File.join(Bundler.rubygems.user_home, ".bundle") return nil if bundle_dir == global_bundle_dir Pathname.new(bundle_dir) end
default_gemfile()
click to toggle source
# File lib/bundler/shared_helpers.rb, line 22 def default_gemfile gemfile = find_gemfile raise GemfileNotFound, "Could not locate Gemfile" unless gemfile Pathname.new(gemfile) end
default_lockfile()
click to toggle source
# File lib/bundler/shared_helpers.rb, line 28 def default_lockfile gemfile = default_gemfile case gemfile.basename.to_s when 'gems.rb' then Pathname.new(gemfile.sub(/.rb$/, '.locked')) else Pathname.new("#{gemfile}.lock") end end
in_bundle?()
click to toggle source
# File lib/bundler/shared_helpers.rb, line 47 def in_bundle? find_gemfile end
pwd()
click to toggle source
# File lib/bundler/shared_helpers.rb, line 57 def pwd Bundler.rubygems.ext_lock.synchronize do Dir.pwd end end
set_bundle_environment()
click to toggle source
# File lib/bundler/shared_helpers.rb, line 76 def set_bundle_environment # Set PATH paths = (ENV["PATH"] || "").split(File::PATH_SEPARATOR) paths.unshift "#{Bundler.bundle_path}/bin" ENV["PATH"] = paths.uniq.join(File::PATH_SEPARATOR) # Set RUBYOPT rubyopt = [ENV["RUBYOPT"]].compact if rubyopt.empty? || rubyopt.first !~ /-rbundler\/setup/ rubyopt.unshift %Q-rbundler/setup| ENV["RUBYOPT"] = rubyopt.join(' ') end # Set RUBYLIB rubylib = (ENV["RUBYLIB"] || "").split(File::PATH_SEPARATOR) rubylib.unshift File.expand_path('../..', __FILE__) ENV["RUBYLIB"] = rubylib.uniq.join(File::PATH_SEPARATOR) end
with_clean_git_env(&block)
click to toggle source
# File lib/bundler/shared_helpers.rb, line 63 def with_clean_git_env(&block) keys = %w[GIT_DIR GIT_WORK_TREE] old_env = keys.inject({}) do |h, k| h.update(k => ENV[k]) end keys.each {|key| ENV.delete(key) } block.call ensure keys.each {|key| ENV[key] = old_env[key] } end
Private Instance Methods
clean_load_path()
click to toggle source
# File lib/bundler/shared_helpers.rb, line 134 def clean_load_path # handle 1.9 where system gems are always on the load path if defined?(::Gem) me = File.expand_path("../../", __FILE__) me = /^#{Regexp.escape(me)}/ loaded_gem_paths = Bundler.rubygems.loaded_gem_paths $LOAD_PATH.reject! do |p| next if File.expand_path(p) =~ me loaded_gem_paths.delete(p) end $LOAD_PATH.uniq! end end
find_directory(*names)
click to toggle source
# File lib/bundler/shared_helpers.rb, line 110 def find_directory(*names) search_up(*names) do |dirname| return dirname if File.directory?(dirname) end end
find_file(*names)
click to toggle source
# File lib/bundler/shared_helpers.rb, line 104 def find_file(*names) search_up(*names) {|filename| return filename if File.file?(filename) } end
find_gemfile()
click to toggle source
# File lib/bundler/shared_helpers.rb, line 97 def find_gemfile given = ENV['BUNDLE_GEMFILE'] return given if given && !given.empty? find_file('Gemfile', 'gems.rb') end
search_up(*names) { |filename| ... }
click to toggle source
# File lib/bundler/shared_helpers.rb, line 116 def search_up(*names) previous = nil current = File.expand_path(SharedHelpers.pwd) until !File.directory?(current) || current == previous if ENV['BUNDLE_SPEC_RUN'] # avoid stepping above the tmp directory when testing return nil if File.file?(File.join(current, 'bundler.gemspec')) end names.each do |name| filename = File.join(current, name) yield filename end current, previous = File.expand_path("..", current), current end end