summaryrefslogtreecommitdiff
path: root/lib/bundler/templates/environment.erb
blob: 2c538e9273f90dbed58d586a57b10c2f39daaba2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
module Bundler
  dir = File.dirname(__FILE__)

<% unless @system_gems -%>
  ENV["GEM_HOME"] = dir
  ENV["GEM_PATH"] = dir
<% end -%>
  ENV["PATH"]     = "#{dir}/<%= bindir %>:#{ENV["PATH"]}"
  ENV["RUBYOPT"]  = "-r#{__FILE__} #{ENV["RUBYOPT"]}"

<% load_paths.each do |load_path| -%>
  $LOAD_PATH.unshift "#{dir}/<%= load_path %>"
<% end -%>

  @gemfile = "#{dir}/<%= filename %>"

<% if @rubygems -%>
  require "rubygems"

  @bundled_specs = {}
<% spec_files.each do |name, path| -%>
  @bundled_specs["<%= name %>"] = eval(File.read("#{dir}/<%= path %>"))
  @bundled_specs["<%= name %>"].loaded_from = "#{dir}/<%= path %>"
<% end -%>

  def self.add_specs_to_loaded_specs
    Gem.loaded_specs.merge! @bundled_specs
  end

  def self.add_specs_to_index
    @bundled_specs.each do |name, spec|
      Gem.source_index.add_spec spec
    end
  end

  add_specs_to_loaded_specs
  add_specs_to_index
<% end -%>
end

<% if @rubygems -%>
module Gem
  def source_index.refresh!
    super
    Bundler.add_specs_to_index
  end
end
<% else -%>
$" << "rubygems.rb"

module Kernel
  def gem(*)
    # Silently ignore calls to gem, since, in theory, everything
    # is activated correctly already.
  end
end

# Define all the Gem errors for gems that reference them.
module Gem
  def self.ruby ; <%= Gem.ruby.inspect %> ; end
  class LoadError < ::LoadError; end
  class Exception < RuntimeError; end
  class CommandLineError < Exception; end
  class DependencyError < Exception; end
  class DependencyRemovalException < Exception; end
  class GemNotInHomeException < Exception ; end
  class DocumentError < Exception; end
  class EndOfYAMLException < Exception; end
  class FilePermissionError < Exception; end
  class FormatException < Exception; end
  class GemNotFoundException < Exception; end
  class InstallError < Exception; end
  class InvalidSpecificationException < Exception; end
  class OperationNotSupportedError < Exception; end
  class RemoteError < Exception; end
  class RemoteInstallationCancelled < Exception; end
  class RemoteInstallationSkipped < Exception; end
  class RemoteSourceException < Exception; end
  class VerificationError < Exception; end
  class SystemExitException < SystemExit; end
end
<% end -%>

require "bundler/runtime"