123456789_123456789_123456789_123456789_123456789_

Class: Gem::Resolver::VendorSet

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Set
Instance Chain:
self, Set
Inherits: Gem::Resolver::Set
Defined in: lib/rubygems/resolver/vendor_set.rb

Overview

A VendorSet represents gems that have been unpacked into a specific directory that contains a gemspec.

This is used for gem dependency file support.

Example:

set = Gem::Resolver::VendorSet.new

set.add_vendor_gem 'rake', 'vendor/rake'

The directory vendor/rake must contain an unpacked rake gem along with a rake.gemspec (watching the given name).

Class Method Summary

Set - Inherited

Instance Attribute Summary

  • #specs readonly Internal use only

    The specifications for this set.

Set - Inherited

#errors

Errors encountered when resolving gems.

#prerelease

When true, allows matching of requests to prerelease gems.

#remote

Set to true to disable network access for this set.

#remote?

When true, this set is allowed to access the network when looking up specifications or dependencies.

Instance Method Summary

Set - Inherited

#find_all

The find_all method must be implemented.

#prefetch

The #prefetch method may be overridden, but this is not necessary.

Constructor Details

.newVendorSet

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rubygems/resolver/vendor_set.rb', line 23

def initialize # :nodoc:
  super()

  @directories = {}
  @specs       = {}
end

Instance Attribute Details

#specs (readonly)

This method is for internal use only.

The specifications for this set.

[ GitHub ]

  
# File 'lib/rubygems/resolver/vendor_set.rb', line 21

attr_reader :specs # :nodoc:

Instance Method Details

#add_vendor_gem(name, directory)

This method is for internal use only.

Adds a specification to the set with the given name which has been unpacked into the given directory.

[ GitHub ]

  
# File 'lib/rubygems/resolver/vendor_set.rb', line 34

def add_vendor_gem(name, directory) # :nodoc:
  gemspec = File.join directory, "#{name}.gemspec"

  spec = Gem::Specification.load gemspec

  raise Gem::GemNotFoundException,
        "unable to find #{gemspec} for gem #{name}" unless spec

  spec.full_gem_path = File.expand_path directory

  @specs[spec.name]  = spec
  @directories[spec] = directory

  spec
end

#find_all(req)

Returns an Array of VendorSpecification objects matching the DependencyRequest req.

[ GitHub ]

  
# File 'lib/rubygems/resolver/vendor_set.rb', line 54

def find_all(req)
  @specs.values.select do |spec|
    req.match? spec
  end.map do |spec|
    source = Gem::Source::Vendor.new @directories[spec]
    Gem::Resolver::VendorSpecification.new self, spec, source
  end
end

#load_spec(name, version, platform, source)

This method is for internal use only.

Loads a spec with the given name. version, platform and source are ignored.

[ GitHub ]

  
# File 'lib/rubygems/resolver/vendor_set.rb', line 67

def load_spec(name, version, platform, source) # :nodoc:
  @specs.fetch name
end

#pretty_print(q)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rubygems/resolver/vendor_set.rb', line 71

def pretty_print(q) # :nodoc:
  q.group 2, '[VendorSet', ']' do
    next if @directories.empty?
    q.breakable

    dirs = @directories.map do |spec, directory|
      "#{spec.full_name}: #{directory}"
    end

    q.seplist dirs do |dir|
      q.text dir
    end
  end
end