Class: Inspec::Plugin::V2::Installer::InstalledVendorSet
- Inherits:
-
Gem::Resolver::Set
- Object
- Gem::Resolver::Set
- Inspec::Plugin::V2::Installer::InstalledVendorSet
- Defined in:
- lib/inspec/plugin/v2/installer.rb
Overview
This class allows 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/32237377/lib/vagrant/bundler.rb#L400 github.com/hashicorp/vagrant/blob/32237377/lib/vagrant/bundler.rb#L565
Instance Method Summary collapse
- #find_all(req) ⇒ Object
-
#initialize ⇒ InstalledVendorSet
constructor
A new instance of InstalledVendorSet.
Constructor Details
#initialize ⇒ InstalledVendorSet
Returns a new instance of InstalledVendorSet.
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 |
# File 'lib/inspec/plugin/v2/installer.rb', line 451 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 spec_dir = if Gem.respond_to? :default_specifications_dir Gem.default_specifications_dir else Gem::Specification.default_specifications_dir end directories = [spec_dir] unless 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
485 486 487 488 489 |
# File 'lib/inspec/plugin/v2/installer.rb', line 485 def find_all(req) @specs.select { |spec| req.match?(spec) }.map do |spec| Gem::Resolver::InstalledSpecification.new(self, spec) end end |