lib/bundler/rubygems_ext.rb in bundler-0.9.26 vs lib/bundler/rubygems_ext.rb in bundler-1.0.0.beta.1

- old
+ new

@@ -1,16 +1,82 @@ -unless defined? Gem - require 'rubygems' - require 'rubygems/specification' +require 'pathname' + +if defined?(Gem::QuickLoader) + # Gem Prelude makes me a sad panda :'( + Gem::QuickLoader.load_full_rubygems_library end +require 'rubygems' +require 'rubygems/specification' + +module Bundler + class DepProxy + + attr_reader :required_by, :__platform, :dep + + def initialize(dep, platform) + @dep, @__platform, @required_by = dep, platform, [] + end + + def hash + @hash ||= dep.hash + end + + def ==(o) + dep == o.dep && __platform == o.__platform + end + + alias eql? == + + def type + @dep.type + end + + def to_s + @dep.to_s + end + + private + + def method_missing(*args) + @dep.send(*args) + end + + end +end + module Gem @loaded_stacks = Hash.new { |h,k| h[k] = [] } + module MatchPlatform + def match_platform(p) + Gem::Platform::RUBY == platform or + platform.nil? or p == platform or + Gem::Platform.new(platform).to_generic == p + end + end + class Specification - attr_accessor :source, :location + attr_accessor :source, :location, :relative_loaded_from + alias_method :rg_full_gem_path, :full_gem_path + alias_method :rg_loaded_from, :loaded_from + + include MatchPlatform + + def full_gem_path + source.respond_to?(:path) ? + Pathname.new(loaded_from).dirname.expand_path.to_s : + rg_full_gem_path + end + + def loaded_from + relative_loaded_from ? + source.path.join(relative_loaded_from).to_s : + rg_loaded_from + end + def load_paths require_paths.map do |require_path| if require_path.include?(full_gem_path) require_path else @@ -24,12 +90,11 @@ end def git_version if @loaded_from && File.exist?(File.join(full_gem_path, ".git")) sha = Dir.chdir(full_gem_path){ `git rev-parse HEAD`.strip } - branch = full_gem_path.split("-")[3] - (branch && branch != sha) ? " #{branch}-#{sha[0...6]}" : " #{sha[0...6]}" + " #{sha[0..6]}" end end def to_gemfile(path = nil) gemfile = "source :gemcutter\n" @@ -77,10 +142,44 @@ end class Dependency attr_accessor :source, :groups + alias eql? == + def to_yaml_properties instance_variables.reject { |p| ["@source", "@groups"].include?(p.to_s) } + end + + def to_lock + out = " #{name}" + unless requirement == Gem::Requirement.default + out << " (#{requirement.to_s})" + end + out + end + end + + class Platform + JAVA = Gem::Platform.new('java') + MSWIN = Gem::Platform.new('mswin32') + MING = Gem::Platform.new('x86-mingw32') + + GENERIC_CACHE = {} + + class << RUBY + def to_generic ; self ; end + end + + GENERICS = [JAVA, MSWIN, MING, RUBY] + + def hash + @cpu.hash + @os.hash + @version.hash + end + + alias eql? == + + def to_generic + GENERIC_CACHE[self] ||= GENERICS.find { |p| self =~ p } || RUBY end end end