This backports base_dir which replaces installation path Rubygems 1.8+
# File lib/bundler/rubygems_integration.rb, line 279 279: def backport_base_dir 280: Gem::Specification.send(:define_method, :base_dir) do 281: return Gem.dir unless loaded_from 282: File.dirname File.dirname loaded_from 283: end 284: end
# File lib/bundler/rubygems_integration.rb, line 286 286: def backport_cache_file 287: Gem::Specification.send(:define_method, :cache_dir) do 288: @cache_dir ||= File.join base_dir, "cache" 289: end 290: 291: Gem::Specification.send(:define_method, :cache_file) do 292: @cache_file ||= File.join cache_dir, "#{full_name}.gem" 293: end 294: end
This backports the correct segment generation code from Rubygems 1.4+ by monkeypatching it into the method in Rubygems 1.3.6 and 1.3.7.
# File lib/bundler/rubygems_integration.rb, line 260 260: def backport_segment_generation 261: Gem::Version.send(:define_method, :segments) do 262: @segments ||= @version.scan(/[0-9]+|[a-z]+/).map do |s| 263: /^\d+$/ =~ s ? s.to_i : s 264: end 265: end 266: end
# File lib/bundler/rubygems_integration.rb, line 296 296: def backport_spec_file 297: Gem::Specification.send(:define_method, :spec_dir) do 298: @spec_dir ||= File.join base_dir, "specifications" 299: end 300: 301: Gem::Specification.send(:define_method, :spec_file) do 302: @spec_file ||= File.join spec_dir, "#{full_name}.gemspec" 303: end 304: end
This backport fixes the marshaling of @segments.
# File lib/bundler/rubygems_integration.rb, line 269 269: def backport_yaml_initialize 270: Gem::Version.send(:define_method, :yaml_initialize) do |tag, map| 271: @version = map['version'] 272: @segments = nil 273: @hash = nil 274: end 275: end
# File lib/bundler/rubygems_integration.rb, line 72 72: def bin_path(gem, bin, ver) 73: Gem.bin_path(gem, bin, ver) 74: end
# File lib/bundler/rubygems_integration.rb, line 68 68: def clear_paths 69: Gem.clear_paths 70: end
# File lib/bundler/rubygems_integration.rb, line 24 24: def configuration 25: Gem.configuration 26: end
# File lib/bundler/rubygems_integration.rb, line 107 107: def download_gem(spec, uri, path) 108: Gem::RemoteFetcher.fetcher.download(spec, uri, path) 109: end
# File lib/bundler/rubygems_integration.rb, line 89 89: def fetch_specs(all, pre, &blk) 90: Gem::SpecFetcher.new.list(all, pre).each(&blk) 91: end
# File lib/bundler/rubygems_integration.rb, line 52 52: def gem_bindir 53: Gem.bindir 54: end
# File lib/bundler/rubygems_integration.rb, line 48 48: def gem_dir 49: Gem.dir 50: end
# File lib/bundler/rubygems_integration.rb, line 60 60: def gem_path 61: Gem.path 62: end
# File lib/bundler/rubygems_integration.rb, line 36 36: def inflate(obj) 37: Gem.inflate(obj) 38: end
# File lib/bundler/rubygems_integration.rb, line 8 8: def loaded_specs(name) 9: Gem.loaded_specs[name] 10: end
# File lib/bundler/rubygems_integration.rb, line 12 12: def mark_loaded(spec) 13: Gem.loaded_specs[spec.name] = spec 14: end
# File lib/bundler/rubygems_integration.rb, line 64 64: def marshal_spec_dir 65: Gem::MARSHAL_SPEC_DIR 66: end
# File lib/bundler/rubygems_integration.rb, line 16 16: def path(obj) 17: obj.to_s 18: end
# File lib/bundler/rubygems_integration.rb, line 20 20: def platforms 21: Gem.platforms 22: end
# File lib/bundler/rubygems_integration.rb, line 80 80: def preserve_paths 81: # this is a no-op outside of Rubygems 1.8 82: yield 83: end
# File lib/bundler/rubygems_integration.rb, line 32 32: def read_binary(path) 33: Gem.read_binary(path) 34: end
# File lib/bundler/rubygems_integration.rb, line 76 76: def refresh 77: Gem.refresh 78: end
Used to make bin stubs that are not created by bundler work under bundler. The new Gem.bin_path only considers gems in specs
# File lib/bundler/rubygems_integration.rb, line 209 209: def replace_bin_path(specs) 210: gem_class = (class << Gem ; self ; end) 211: gem_class.send(:remove_method, :bin_path) 212: gem_class.send(:define_method, :bin_path) do |name, *args| 213: exec_name = args.first 214: 215: if exec_name == 'bundle' 216: return ENV['BUNDLE_BIN_PATH'] 217: end 218: 219: spec = nil 220: 221: if exec_name 222: spec = specs.find { |s| s.executables.include?(exec_name) } 223: spec or raise Gem::Exception, "can't find executable #{exec_name}" 224: else 225: spec = specs.find { |s| s.name == name } 226: exec_name = spec.default_executable or raise Gem::Exception, "no default executable for #{spec.full_name}" 227: end 228: 229: gem_bin = File.join(spec.full_gem_path, spec.bindir, exec_name) 230: gem_from_path_bin = File.join(File.dirname(spec.loaded_from), spec.bindir, exec_name) 231: File.exist?(gem_bin) ? gem_bin : gem_from_path_bin 232: end 233: end
Replace or hook into Rubygems to provide a bundlerized view of the world.
# File lib/bundler/rubygems_integration.rb, line 245 245: def replace_entrypoints(specs) 246: reverse_rubygems_kernel_mixin 247: 248: replace_gem(specs) 249: 250: stub_rubygems(specs) 251: 252: replace_bin_path(specs) 253: replace_refresh 254: 255: Gem.clear_paths 256: end
# File lib/bundler/rubygems_integration.rb, line 123 123: def replace_gem(specs) 124: executables = specs.map { |s| s.executables }.flatten 125: 126: ::Kernel.send(:define_method, :gem) do |dep, *reqs| 127: if executables.include? File.basename(caller.first.split(':').first) 128: return 129: end 130: reqs.pop if reqs.last.is_a?(Hash) 131: 132: unless dep.respond_to?(:name) && dep.respond_to?(:requirement) 133: dep = Gem::Dependency.new(dep, reqs) 134: end 135: 136: spec = specs.find { |s| s.name == dep.name } 137: 138: if spec.nil? 139: 140: e = Gem::LoadError.new "#{dep.name} is not part of the bundle. Add it to Gemfile." 141: e.name = dep.name 142: if e.respond_to?(:requirement=) 143: e.requirement = dep.requirement 144: else 145: e.version_requirement = dep.requirement 146: end 147: raise e 148: elsif dep !~ spec 149: e = Gem::LoadError.new "can't activate #{dep}, already activated #{spec.full_name}. " "Make sure all dependencies are added to Gemfile." 150: e.name = dep.name 151: if e.respond_to?(:requirement=) 152: e.requirement = dep.requirement 153: else 154: e.version_requirement = dep.requirement 155: end 156: raise e 157: end 158: 159: true 160: end 161: end
Because Bundler has a static view of what specs are available, we don’t #, so stub it out.
# File lib/bundler/rubygems_integration.rb, line 237 237: def replace_refresh 238: gem_class = (class << Gem ; self ; end) 239: gem_class.send(:remove_method, :refresh) 240: gem_class.send(:define_method, :refresh) { } 241: end
# File lib/bundler/rubygems_integration.rb, line 111 111: def reverse_rubygems_kernel_mixin 112: # Disable rubygems' gem activation system 113: ::Kernel.class_eval do 114: if private_method_defined?(:gem_original_require) 115: alias rubygems_require require 116: alias require gem_original_require 117: end 118: 119: undef gem 120: end 121: end
# File lib/bundler/rubygems_integration.rb, line 28 28: def ruby_engine 29: Gem.ruby_engine 30: end
# File lib/bundler/rubygems_integration.rb, line 44 44: def sources 45: Gem.sources 46: end
# File lib/bundler/rubygems_integration.rb, line 40 40: def sources=(val) 41: Gem.sources = val 42: end
# File lib/bundler/rubygems_integration.rb, line 103 103: def spec_from_gem(path) 104: Gem::Format.from_file_by_path(path).spec 105: end
# File lib/bundler/rubygems_integration.rb, line 174 174: def stub_source_index137(specs) 175: # Rubygems versions lower than 1.7 use SourceIndex#from_gems_in 176: source_index_class = (class << Gem::SourceIndex ; self ; end) 177: source_index_class.send(:remove_method, :from_gems_in) 178: source_index_class.send(:define_method, :from_gems_in) do |*args| 179: source_index = Gem::SourceIndex.new 180: source_index.spec_dirs = *args 181: source_index.add_specs(*specs) 182: source_index 183: end 184: end
# File lib/bundler/rubygems_integration.rb, line 186 186: def stub_source_index170(specs) 187: Gem::SourceIndex.send(:alias_method, :old_initialize, :initialize) 188: Gem::SourceIndex.send(:define_method, :initialize) do |*args| 189: @gems = {} 190: # You're looking at this thinking: Oh! This is how I make those 191: # rubygems deprecations go away! 192: # 193: # You'd be correct BUT using of this method in production code 194: # must be approved by the rubygems team itself! 195: # 196: # This is your warning. If you use this and don't have approval 197: # we can't protect you. 198: # 199: Deprecate.skip_during do 200: self.spec_dirs = *args 201: add_specs(*specs) 202: end 203: end 204: end
# File lib/bundler/rubygems_integration.rb, line 85 85: def ui=(obj) 86: Gem::DefaultUserInteraction.ui = obj 87: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.