Module: Bundler::SharedHelpers

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

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



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

def chdir(dir, &blk)
  Bundler.rubygems.ext_lock.synchronize do
    Dir.chdir dir, &blk
  end
end

#const_get_safely(constant_name, namespace) ⇒ Object



114
115
116
117
118
119
# File 'lib/bundler/shared_helpers.rb', line 114

def const_get_safely(constant_name, namespace)
  const_in_namespace = namespace.constants.include?(constant_name.to_s) ||
    namespace.constants.include?(constant_name.to_sym)
  return nil unless const_in_namespace
  namespace.const_get(constant_name)
end

#default_bundle_dirObject



38
39
40
41
42
43
44
45
46
# File 'lib/bundler/shared_helpers.rb', line 38

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_gemfileObject

Raises:



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

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

#default_lockfileObject



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

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

#filesystem_access(path, action = :write) { ... } ⇒ Object

Rescues permissions errors raised by file system operations (ie. Errno:EACCESS, Errno::EAGAIN) and raises more friendly errors instead.

Examples:

filesystem_access("vendor/cache", :write) do
  FileUtils.mkdir_p("vendor/cache")
end

Parameters:

  • path (String)

    the path that the action will be attempted to

  • action (Symbol, #to_s) (defaults to: :write)

    the type of operation that will be performed. For example: :write, :read, :exec

Yields:

  • path

Raises:

See Also:

  • Bundler::SharedHelpers.{Bundler{Bundler::PermissionError}


104
105
106
107
108
109
110
111
112
# File 'lib/bundler/shared_helpers.rb', line 104

def filesystem_access(path, action = :write)
  yield path
rescue Errno::EACCES
  raise PermissionError.new(path, action)
rescue Errno::EAGAIN
  raise TemporaryResourceError.new(path, action)
rescue Errno::EPROTO
  raise VirtualProtocolError.new
end

#in_bundle?Boolean

Returns:

  • (Boolean)


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

def in_bundle?
  find_gemfile
end

#pwdObject



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

def pwd
  Bundler.rubygems.ext_lock.synchronize do
    Pathname.pwd
  end
end

#set_bundle_environmentObject



77
78
79
80
81
82
# File 'lib/bundler/shared_helpers.rb', line 77

def set_bundle_environment
  set_bundle_variables
  set_path
  set_rubyopt
  set_rubylib
end

#with_clean_git_env(&block) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/bundler/shared_helpers.rb', line 64

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