Class: Inspec::Plugin::V2::Installer::InstalledVendorSet

Inherits:
Gem::Resolver::Set
  • Object
show all
Defined in:
lib/inspec/plugin/v2/installer.rb

Overview

This class alows us to build a Resolver set with the gems that are already included either with Ruby or with the InSpec install

This code is heavily based on: github.com/hashicorp/vagrant/blob/master/lib/vagrant/bundler.rb#L400 github.com/hashicorp/vagrant/blob/master/lib/vagrant/bundler.rb#L565

Instance Method Summary collapse

Constructor Details

#initializeInstalledVendorSet

Returns a new instance of InstalledVendorSet.



403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
# File 'lib/inspec/plugin/v2/installer.rb', line 403

def initialize
  super
  @remote = false
  @specs = []

  # Grab any pre loaded gems
  Gem::Specification.find_all do |spec|
    @specs << spec
  end

  # find all gem specification directories
  directories = [Gem::Specification.default_specifications_dir]
  if !defined?(::Bundler)
    # add in any others that do not start with the user directory
    directories += Gem::Specification.dirs.find_all do |path|
      !path.start_with?(Gem.user_dir)
    end
  end

  # add them all to the specs array
  Gem::Specification.each_spec(directories) do |spec|
    @specs << spec
  end

  # resolver expects one of each spec so uniq here.
  @specs.uniq!
end

Instance Method Details

#find_all(req) ⇒ Object



431
432
433
434
435
# File 'lib/inspec/plugin/v2/installer.rb', line 431

def find_all(req)
  @specs.select { |spec| req.match?(spec) }.map do |spec|
    Gem::Resolver::InstalledSpecification.new(self, spec)
  end
end