Bundler::SharedHelpers

Attributes

gem_loaded[RW]

Public Instance Methods

default_gemfile() click to toggle source
    # File lib/bundler/shared_helpers.rb, line 19
19:     def default_gemfile
20:       gemfile = find_gemfile
21:       gemfile or raise GemfileNotFound, "Could not locate Gemfile"
22:       Pathname.new(gemfile)
23:     end
default_lockfile() click to toggle source
    # File lib/bundler/shared_helpers.rb, line 25
25:     def default_lockfile
26:       Pathname.new("#{default_gemfile}.lock")
27:     end
in_bundle?() click to toggle source
    # File lib/bundler/shared_helpers.rb, line 29
29:     def in_bundle?
30:       find_gemfile
31:     end

Private Instance Methods

clean_load_path() click to toggle source
    # File lib/bundler/shared_helpers.rb, line 48
48:     def clean_load_path
49:       # handle 1.9 where system gems are always on the load path
50:       if defined?(::Gem)
51:         me = File.expand_path("../../", __FILE__)
52:         $LOAD_PATH.reject! do |p|
53:           next if File.expand_path(p).include?(me)
54:           p != File.dirname(__FILE__) &&
55:             Gem.path.any? { |gp| p.include?(gp) }
56:         end
57:         $LOAD_PATH.uniq!
58:       end
59:     end
cripple_rubygems(specs) click to toggle source
     # File lib/bundler/shared_helpers.rb, line 73
 73:     def cripple_rubygems(specs)
 74:       reverse_rubygems_kernel_mixin
 75: 
 76:       executables = specs.map { |s| s.executables }.flatten
 77:       Gem.source_index # ensure RubyGems is fully loaded
 78: 
 79:      ::Kernel.class_eval do
 80:         private
 81:         def gem(*) ; end
 82:       end
 83: 
 84:       ::Kernel.send(:define_method, :gem) do |dep, *reqs|
 85:         if executables.include? File.basename(caller.first.split(':').first)
 86:           return
 87:         end
 88:         opts = reqs.last.is_a?(Hash) ? reqs.pop : {}
 89: 
 90:         unless dep.respond_to?(:name) && dep.respond_to?(:requirement)
 91:           dep = Gem::Dependency.new(dep, reqs)
 92:         end
 93: 
 94:         spec = specs.find  { |s| s.name == dep.name }
 95: 
 96:         if spec.nil?
 97:           e = Gem::LoadError.new "#{dep.name} is not part of the bundle. Add it to Gemfile."
 98:           e.name = dep.name
 99:           e.version_requirement = dep.requirement
100:           raise e
101:         elsif dep !~ spec
102:           e = Gem::LoadError.new "can't activate #{dep}, already activated #{spec.full_name}. "                                   "Make sure all dependencies are added to Gemfile."
103:           e.name = dep.name
104:           e.version_requirement = dep.requirement
105:           raise e
106:         end
107: 
108:         true
109:       end
110: 
111:       # === Following hacks are to improve on the generated bin wrappers ===
112: 
113:       # Yeah, talk about a hack
114:       source_index_class = (class << Gem::SourceIndex ; self ; end)
115:       source_index_class.send(:define_method, :from_gems_in) do |*args|
116:         source_index = Gem::SourceIndex.new
117:         source_index.spec_dirs = *args
118:         source_index.add_specs(*specs)
119:         source_index
120:       end
121: 
122:       # OMG more hacks
123:       gem_class = (class << Gem ; self ; end)
124:       gem_class.send(:define_method, :refresh) { }
125:       gem_class.send(:define_method, :bin_path) do |name, *args|
126:         exec_name, *reqs = args
127: 
128:         if exec_name == 'bundle'
129:           return ENV['BUNDLE_BIN_PATH']
130:         end
131: 
132:         spec = nil
133: 
134:         if exec_name
135:           spec = specs.find { |s| s.executables.include?(exec_name) }
136:           spec or raise Gem::Exception, "can't find executable #{exec_name}"
137:         else
138:           spec = specs.find  { |s| s.name == name }
139:           exec_name = spec.default_executable or raise Gem::Exception, "no default executable for #{spec.full_name}"
140:         end
141: 
142:         gem_bin = File.join(spec.full_gem_path, spec.bindir, exec_name)
143:         gem_from_path_bin = File.join(File.dirname(spec.loaded_from), spec.bindir, exec_name)
144:         File.exist?(gem_bin) ? gem_bin : gem_from_path_bin
145:       end
146: 
147:       Gem.clear_paths
148:     end
find_gemfile() click to toggle source
    # File lib/bundler/shared_helpers.rb, line 35
35:     def find_gemfile
36:       return ENV['BUNDLE_GEMFILE'] if ENV['BUNDLE_GEMFILE']
37: 
38:       previous = nil
39:       current  = File.expand_path(Dir.pwd)
40: 
41:       until !File.directory?(current) || current == previous
42:         filename = File.join(current, 'Gemfile')
43:         return filename if File.file?(filename)
44:         current, previous = File.expand_path("..", current), current
45:       end
46:     end
gem(*) click to toggle source
    # File lib/bundler/shared_helpers.rb, line 81
81:         def gem(*) ; end
reverse_rubygems_kernel_mixin() click to toggle source
    # File lib/bundler/shared_helpers.rb, line 61
61:     def reverse_rubygems_kernel_mixin
62:       # Disable rubygems' gem activation system
63:       ::Kernel.class_eval do
64:         if private_method_defined?(:gem_original_require)
65:           alias rubygems_require require
66:           alias require gem_original_require
67:         end
68: 
69:         undef gem
70:       end
71:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.