class Bundler::DirectorySource

def ==(other)

def ==(other)
  # TMP HAX
  other.is_a?(DirectorySource)
end

def add_spec(path, name, version, require_paths = %w(lib))

def add_spec(path, name, version, require_paths = %w(lib))
  raise DirectorySourceError, "already have a gem defined for '#{path}'" if @specs[path.to_s]
  @specs[path.to_s] = Gem::Specification.new do |s|
    s.name     = name
    s.version  = Gem::Version.new(version)
  end
end

def can_be_local?

def can_be_local?
  true
end

def download(spec)

def download(spec)
  # Nothing needed here
end

def gems

def gems
  @gems ||= begin
    # Locate all gemspecs from the directory
    specs = locate_gemspecs
    specs = merge_defined_specs(specs)
    required_specs.each do |required|
      unless specs.any? {|k,v| v.name == required }
        raise DirectorySourceError, "No gemspec for '#{required}' was found in" \
          " '#{location}'. Please explicitly specify a version."
      end
    end
    process_source_gems(specs)
  end
end

def initialize(bundle, options)

def initialize(bundle, options)
  super
  if options[:location]
    @location = Pathname.new(options[:location]).expand_path
  end
  @glob           = options[:glob] || "**/*.gemspec"
  @specs          = {}
  @required_specs = []
end

def locate_gemspecs

def locate_gemspecs
  Dir["#{location}/#{@glob}"].inject({}) do |specs, file|
    file = Pathname.new(file)
    if spec = eval(File.read(file)) # and validate_gemspec(file.dirname, spec)
      spec.location = file.dirname.expand_path
      specs[spec.full_name] = spec
    end
    specs
  end
end

def merge_defined_specs(specs)

def merge_defined_specs(specs)
  @specs.each do |path, spec|
    # Set the spec location
    spec.location = "#{location}/#{path}"
    if existing = specs.values.find { |s| s.name == spec.name }
      if existing.version != spec.version
        raise DirectorySourceError, "The version you specified for #{spec.name}" \
          " is #{spec.version}. The gemspec is #{existing.version}."
      # Not sure if this is needed
      # ====
      # elsif File.expand_path(existing.location) != File.expand_path(spec.location)
      #   raise DirectorySourceError, "The location you specified for #{spec.name}" \
      #     " is '#{spec.location}'. The gemspec was found at '#{existing.location}'."
      end
    # elsif !validate_gemspec(spec.location, spec)
    #   raise "Your gem definition is not valid: #{spec}"
    else
      specs[spec.full_name] = spec
    end
  end
  specs
end

def to_s

def to_s
  "directory: '#{location}'"
end

def validate_gemspec(path, spec)

def validate_gemspec(path, spec)
  path = Pathname.new(path)
  msg  = "Gemspec for #{spec.name} (#{spec.version}) is invalid:"
  # Check the require_paths
  (spec.require_paths || []).each do |require_path|
    unless path.join(require_path).directory?
      Bundler.logger.warn "#{msg} Missing require path: '#{require_path}'"
      return false
    end
  end
  # Check the executables
  (spec.executables || []).each do |exec|
    unless path.join(spec.bindir, exec).file?
      Bundler.logger.warn "#{msg} Missing executable: '#{File.join(spec.bindir, exec)}'"
      return false
    end
  end
  true
end