Module: Bundler::SharedHelpers

Extended by:
SharedHelpers
Included in:
Runtime, SharedHelpers
Defined in:
lib/bundler/shared_helpers.rb

Constant Summary collapse

CHDIR_MONITOR =
Monitor.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#gem_loadedObject

Returns the value of attribute gem_loaded


21
22
23
# File 'lib/bundler/shared_helpers.rb', line 21

def gem_loaded
  @gem_loaded
end

Instance Method Details

#chdir(dir, &blk) ⇒ Object


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

def chdir(dir, &blk)
  chdir_monitor.synchronize do
    Dir.chdir dir, &blk
  end
end

#chdir_monitorObject


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

def chdir_monitor
  CHDIR_MONITOR
end

#default_gemfileObject

Raises:


24
25
26
27
28
# File 'lib/bundler/shared_helpers.rb', line 24

def default_gemfile
  gemfile = find_gemfile
  raise GemfileNotFound, "Could not locate Gemfile" unless gemfile
  Pathname.new(gemfile)
end

#default_lockfileObject


30
31
32
33
34
35
36
37
# File 'lib/bundler/shared_helpers.rb', line 30

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?Boolean

Returns:

  • (Boolean)

39
40
41
# File 'lib/bundler/shared_helpers.rb', line 39

def in_bundle?
  find_gemfile
end

#pwdObject


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

def pwd
  chdir_monitor.synchronize do
    Dir.pwd
  end
end

#with_clean_git_env(&block) ⇒ Object


59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/bundler/shared_helpers.rb', line 59

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