Class: Bundler::Plumber::Scanner

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler/plumber/scanner.rb

Defined Under Namespace

Classes: UnpatchedGem

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root = Dir.pwd, gemfile_lock = 'Gemfile.lock') ⇒ Scanner

Initializes a scanner.

Parameters:

  • root (String) (defaults to: Dir.pwd)

    The path to the project root.

  • gemfile_lock (String) (defaults to: 'Gemfile.lock')

    Alternative name for the Gemfile.lock file.


57
58
59
60
61
62
63
# 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

Instance Attribute Details

#databaseDatabase (readonly)

The advisory database

Returns:


38
39
40
# File 'lib/bundler/plumber/scanner.rb', line 38

def database
  @database
end

#lockfileBundler::LockfileParser (readonly)

The parsed Gemfile.lock from the project

Returns:

  • (Bundler::LockfileParser)

46
47
48
# File 'lib/bundler/plumber/scanner.rb', line 46

def lockfile
  @lockfile
end

#rootObject (readonly)

Project root directory


41
42
43
# File 'lib/bundler/plumber/scanner.rb', line 41

def root
  @root
end

Instance Method Details

#scan(options = {}) {|result| ... } ⇒ Enumerator

Scans the project for issues.

Parameters:

  • options (Hash) (defaults to: {})

    Additional options.

Options Hash (options):

  • :ignore (Array<String>)

    The advisories to ignore.

Yields:

  • (result)

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

Returns:

  • (Enumerator)

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


80
81
82
83
84
85
86
87
88
89
# File 'lib/bundler/plumber/scanner.rb', line 80

def scan(options={},&block)
  return enum_for(__method__, options) unless block

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

  scan_specs(options, &block)

  return self
end

#scan_specs(options = {}) {|result| ... } ⇒ Enumerator

Scans the gem sources in the lockfile.

Parameters:

  • options (Hash) (defaults to: {})

    Additional options.

Options Hash (options):

  • :ignore (Array<String>)

    The advisories to ignore.

Yields:

  • (result)

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

Yield Parameters:

Returns:

  • (Enumerator)

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

Since:

  • 0.4.0


113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/bundler/plumber/scanner.rb', line 113

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|

      # TODO this logic should be modified for rubymem
      #unless (ignore.include?(advisory.cve_id) || ignore.include?(advisory.osvdb_id))
      #  yield UnpatchedGem.new(gem,advisory)
      #end
      yield UnpatchedGem.new(gem, advisory)
    end
  end
end