moduleBundlerclassRubygemsIntegrationdefinitialize# Work around a RubyGems bugconfigurationenddefloaded_specs(name)Gem.loaded_specs[name]enddefmark_loaded(spec)Gem.loaded_specs[spec.name]=specenddefpath(obj)obj.to_senddefplatformsGem.platformsenddefconfigurationGem.configurationenddefruby_engineGem.ruby_engineenddefread_binary(path)Gem.read_binary(path)enddefinflate(obj)Gem.inflate(obj)enddefsources=(val)Gem.sources=valenddefsourcesGem.sourcesenddefgem_dirGem.direnddefgem_bindirGem.bindirenddefuser_homeGem.user_homeenddefgem_pathGem.pathenddefmarshal_spec_dirGem::MARSHAL_SPEC_DIRenddefclear_pathsGem.clear_pathsenddefbin_path(gem,bin,ver)Gem.bin_path(gem,bin,ver)enddefrefreshGem.refreshenddefpreserve_paths# this is a no-op outside of Rubygems 1.8yieldenddefui=(obj)Gem::DefaultUserInteraction.ui=objenddeffetch_specs(all,pre,&blk)Gem::SpecFetcher.new.list(all,pre).each(&blk)enddefwith_build_args(args)old_args=Gem::Command.build_argsbeginGem::Command.build_args=argsyieldensureGem::Command.build_args=old_argsendenddefspec_from_gem(path)Gem::Format.from_file_by_path(path).specenddefdownload_gem(spec,uri,path)Gem::RemoteFetcher.fetcher.download(spec,uri,path)enddefreverse_rubygems_kernel_mixin# Disable rubygems' gem activation system::Kernel.class_evaldoifprivate_method_defined?(:gem_original_require)aliasrubygems_requirerequirealiasrequiregem_original_requireendundefgemendenddefreplace_gem(specs)executables=specs.map{|s|s.executables}.flatten::Kernel.send(:define_method,:gem)do|dep,*reqs|ifexecutables.include?File.basename(caller.first.split(':').first)returnendreqs.popifreqs.last.is_a?(Hash)unlessdep.respond_to?(:name)&&dep.respond_to?(:requirement)dep=Gem::Dependency.new(dep,reqs)endspec=specs.find{|s|s.name==dep.name}ifspec.nil?e=Gem::LoadError.new"#{dep.name} is not part of the bundle. Add it to Gemfile."e.name=dep.nameife.respond_to?(:requirement=)e.requirement=dep.requirementelsee.version_requirement=dep.requirementendraiseeelsifdep!~spece=Gem::LoadError.new"can't activate #{dep}, already activated #{spec.full_name}. "\"Make sure all dependencies are added to Gemfile."e.name=dep.nameife.respond_to?(:requirement=)e.requirement=dep.requirementelsee.version_requirement=dep.requirementendraiseeendtrueendendifdefined?::DeprecateDeprecate=::Deprecateelsifdefined?Gem::DeprecateDeprecate=Gem::DeprecateelseclassDeprecatedefskip_during;yield;endendenddefstub_source_index137(specs)# Rubygems versions lower than 1.7 use SourceIndex#from_gems_insource_index_class=(class<<Gem::SourceIndex;self;end)source_index_class.send(:remove_method,:from_gems_in)source_index_class.send(:define_method,:from_gems_in)do|*args|source_index=Gem::SourceIndex.newsource_index.spec_dirs=*argssource_index.add_specs(*specs)source_indexendenddefstub_source_index170(specs)Gem::SourceIndex.send(:alias_method,:old_initialize,:initialize)Gem::SourceIndex.send(:define_method,:initialize)do|*args|@gems={}# You're looking at this thinking: Oh! This is how I make those# rubygems deprecations go away!## You'd be correct BUT using of this method in production code# must be approved by the rubygems team itself!## This is your warning. If you use this and don't have approval# we can't protect you.#Deprecate.skip_duringdoself.spec_dirs=*argsadd_specs(*specs)endendend# Used to make bin stubs that are not created by bundler work# under bundler. The new Gem.bin_path only considers gems in# +specs+defreplace_bin_path(specs)gem_class=(class<<Gem;self;end)gem_class.send(:remove_method,:bin_path)gem_class.send(:define_method,:bin_path)do|name,*args|exec_name=args.firstifexec_name=='bundle'returnENV['BUNDLE_BIN_PATH']endspec=nilifexec_namespec=specs.find{|s|s.executables.include?(exec_name)}specorraiseGem::Exception,"can't find executable #{exec_name}"elsespec=specs.find{|s|s.name==name}exec_name=spec.default_executableorraiseGem::Exception,"no default executable for #{spec.full_name}"endgem_bin=File.join(spec.full_gem_path,spec.bindir,exec_name)gem_from_path_bin=File.join(File.dirname(spec.loaded_from),spec.bindir,exec_name)File.exist?(gem_bin)?gem_bin:gem_from_path_binendend# Because Bundler has a static view of what specs are available,# we don't #refresh, so stub it out.defreplace_refreshgem_class=(class<<Gem;self;end)gem_class.send(:remove_method,:refresh)gem_class.send(:define_method,:refresh){}end# Replace or hook into Rubygems to provide a bundlerized view# of the world.defreplace_entrypoints(specs)reverse_rubygems_kernel_mixinreplace_gem(specs)stub_rubygems(specs)replace_bin_path(specs)replace_refreshGem.clear_pathsend# 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.defbackport_segment_generationGem::Version.send(:define_method,:segments)do@segments||=@version.scan(/[0-9]+|[a-z]+/i).mapdo|s|/^\d+$/=~s?s.to_i:sendendend# This backport fixes the marshaling of @segments.defbackport_yaml_initializeGem::Version.send(:define_method,:yaml_initialize)do|tag,map|@version=map['version']@segments=nil@hash=nilendend# This backports base_dir which replaces installation path# Rubygems 1.8+defbackport_base_dirGem::Specification.send(:define_method,:base_dir)doreturnGem.dirunlessloaded_fromFile.dirnameFile.dirnameloaded_fromendenddefbackport_cache_fileGem::Specification.send(:define_method,:cache_dir)do@cache_dir||=File.joinbase_dir,"cache"endGem::Specification.send(:define_method,:cache_file)do@cache_file||=File.joincache_dir,"#{full_name}.gem"endenddefbackport_spec_fileGem::Specification.send(:define_method,:spec_dir)do@spec_dir||=File.joinbase_dir,"specifications"endGem::Specification.send(:define_method,:spec_file)do@spec_file||=File.joinspec_dir,"#{full_name}.gemspec"endend# Rubygems 1.4 through 1.6classLegacy<RubygemsIntegrationdefinitializesuperbackport_base_dirbackport_cache_filebackport_spec_filebackport_yaml_initializeenddefstub_rubygems(specs)stub_source_index137(specs)enddefall_specsGem.source_index.gems.valuesenddeffind_name(name)Gem.source_index.find_name(name)endend# Rubygems versions 1.3.6 and 1.3.7classAncient<Legacydefinitializesuperbackport_segment_generationendend# Rubygems 1.7classTransitional<Legacydefstub_rubygems(specs)stub_source_index170(specs)endend# Rubygems 1.8.5classModern<RubygemsIntegrationdefstub_rubygems(specs)Gem::Specification.all=specsGem.post_reset{Gem::Specification.all=specs}stub_source_index170(specs)enddefall_specsGem::Specification.to_aenddeffind_name(name)Gem::Specification.find_all_by_namenameendend# Rubygems 1.8.0 to 1.8.4classAlmostModern<Modern# Rubygems [>= 1.8.0, < 1.8.5] has a bug that changes Gem.dir whenever# you call Gem::Installer#install with an :install_dir set. We have to# change it back for our sudo mode to work.defpreserve_pathsold_dir,old_path=gem_dir,gem_pathyieldGem.use_paths(old_dir,old_path)endendendifGem::Version.new(Gem::VERSION)>=Gem::Version.new('1.8.5')@rubygems=RubygemsIntegration::Modern.newelsifGem::Version.new(Gem::VERSION)>=Gem::Version.new('1.8.0')@rubygems=RubygemsIntegration::AlmostModern.newelsifGem::Version.new(Gem::VERSION)>=Gem::Version.new('1.7.0')@rubygems=RubygemsIntegration::Transitional.newelsifGem::Version.new(Gem::VERSION)>=Gem::Version.new('1.4.0')@rubygems=RubygemsIntegration::Legacy.newelse# Rubygems 1.3.6 and 1.3.7@rubygems=RubygemsIntegration::Ancient.newendclass<<selfattr_reader:rubygemsendend