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



116
117
118
119
120
121
# File 'lib/bundler/shared_helpers.rb', line 116

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).untaint
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.untaint
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
113
114
# File 'lib/bundler/shared_helpers.rb', line 104

def filesystem_access(path, action = :write)
  yield path.dup.untaint
rescue Errno::EACCES
  raise PermissionError.new(path, action)
rescue Errno::EAGAIN
  raise TemporaryResourceError.new(path, action)
rescue Errno::EPROTO
  raise VirtualProtocolError.new
rescue *[const_get_safely(:ENOTSUP, Errno)].compact
  raise OperationNotSupportedError.new(path, action)
end

#in_bundle?Boolean

Returns:

  • (Boolean)


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

def in_bundle?
  find_gemfile
end

#major_deprecation(message) ⇒ Object



123
124
125
126
127
128
# File 'lib/bundler/shared_helpers.rb', line 123

def major_deprecation(message)
  return unless prints_major_deprecations?
  @major_deprecation_ui ||= Bundler::UI::Shell.new("no-color" => true)
  ui = Bundler.ui.is_a?(@major_deprecation_ui.class) ? Bundler.ui : @major_deprecation_ui
  ui.warn("[DEPRECATED FOR #{Bundler::VERSION.split(".").first.to_i + 1}.0] #{message}")
end


130
131
132
133
134
135
136
137
# File 'lib/bundler/shared_helpers.rb', line 130

def print_major_deprecations!
  deprecate_gemfile(find_gemfile) if find_gemfile == find_file("Gemfile")
  if RUBY_VERSION < "2"
    major_deprecation("Bundler will only support ruby >= 2.0, you are running #{RUBY_VERSION}")
  end
  return if Bundler.rubygems.provides?(">= 2")
  major_deprecation("Bundler will only support rubygems >= 2.0, you are running #{Bundler.rubygems.version}")
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