class Bundler::Plumber::Scanner

Constants

UnpatchedGem

Represents a gem that is covered by an Advisory

Attributes

database[R]

The advisory database

@return [Database]

lockfile[R]

The parsed `Gemfile.lock` from the project

@return [Bundler::LockfileParser]

root[R]

Project root directory

Public Class Methods

new(root=Dir.pwd,gemfile_lock='Gemfile.lock') click to toggle source

Initializes a scanner.

@param [String] root

The path to the project root.

@param [String] gemfile_lock

Alternative name for the `Gemfile.lock` file.
# File lib/bundler/plumber/scanner.rb, line 57
def initialize(root=Dir.pwd,gemfile_lock='Gemfile.lock')
  @root     = File.expand_path(root)
  @database = Database.new
  @lockfile = LockfileParser.new(
    File.read(File.join(@root,gemfile_lock))
  )
end

Public Instance Methods

scan(options={},&block) click to toggle source

Scans the project for issues.

@param [Hash] options

Additional options.

@option options [Array<String>] :ignore

The advisories to ignore.

@yield [result]

The given block will be passed the results of the scan.

@return [Enumerator]

If no block is given, an Enumerator will be returned.
# File lib/bundler/plumber/scanner.rb, line 80
def scan(options={},&block)
  return enum_for(__method__, options) unless block

  scan_specs(options, &block)

  return self
end
scan_specs(options={}) { |unpatched_gem| ... } click to toggle source

Scans the gem sources in the lockfile.

@param [Hash] options

Additional options.

@option options [Array<String>] :ignore

The advisories to ignore.

@yield [result]

The given block will be passed the results of the scan.

@yieldparam [UnpatchedGem] result

A result from the scan.

@return [Enumerator]

If no block is given, an Enumerator will be returned.

@api semipublic

@since 0.4.0

# File lib/bundler/plumber/scanner.rb, line 110
def scan_specs(options={})
  return enum_for(__method__, options) unless block_given?

  ignore = Set[]
  ignore += options[:ignore] if options[:ignore]

  @lockfile.specs.each do |gem|
    @database.check_gem(gem) do |advisory|
      gem_and_id = "#{advisory.gem}-#{advisory.id}"
      yield UnpatchedGem.new(gem,advisory) unless ignore.include?(gem_and_id)
    end
  end
end