Class: Dobby::Scanner

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

Overview

Compares a Database and Array<Package> to discover what defects affect a system.

Constant Summary collapse

FLAG_FILTER_ALL =
:all
FLAG_FILTER_ALLOWED =
:allowed
FLAG_FILTER_WHITELISTED =
:whitelisted
FLAG_FILTER_DEFAULT =
:default
DEFECT_FILTER_DEFAULT =
:default
DEFECT_FILTER_FIXED =
:only_fixed
VERSION_FILTER_TARGET =
:target
VERSION_FILTER_DEFAULT =
:default

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(packages, database) ⇒ Scanner

Returns a new instance of Scanner.

Parameters:



22
23
24
25
26
27
# File 'lib/dobby/scanner.rb', line 22

def initialize(packages, database)
  @packages = packages
  @database = database

  @results = Hash.new { |h, k| h[k] = [] }
end

Instance Attribute Details

#databaseObject (readonly)

Returns the value of attribute database.



7
8
9
# File 'lib/dobby/scanner.rb', line 7

def database
  @database
end

#packagesObject

Returns the value of attribute packages.



7
8
9
# File 'lib/dobby/scanner.rb', line 7

def packages
  @packages
end

#resultsObject (readonly)

Returns the value of attribute results.



7
8
9
# File 'lib/dobby/scanner.rb', line 7

def results
  @results
end

Instance Method Details

#scan(defect_filter: DEFECT_FILTER_DEFAULT, flag_filter: FLAG_FILTER_DEFAULT, version_filter: VERSION_FILTER_DEFAULT) ⇒ Object

Determine which packages are affected by which defects.

Order of filter processing, from first to last:

  1. Flag
  2. Defect
  3. Version

Parameters:

  • [Symbol] (Hash)

    a customizable set of options



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/dobby/scanner.rb', line 64

def scan(defect_filter: DEFECT_FILTER_DEFAULT,
         flag_filter: FLAG_FILTER_DEFAULT,
         version_filter: VERSION_FILTER_DEFAULT)
  @results.clear
  packages.each do |package|
    scan_results = scan_one(package: package,
                            defect_filter: defect_filter,
                            flag_filter: flag_filter,
                            version_filter: version_filter)
    @results.merge! scan_results
  end
  results
end

#scan_by_targetObject

Note:

Packages that do not have a target version set are skipped.

Determine which defects are resolved by upgrading to a target version.

Given:

  • A Package at version 1 and a target version of 3
  • A Defect, D1, with a fix version of 2
  • A Defect, D2, with a fix version of 3
  • A Defect, D3, with a fix version of 4

Returns D1 and D2, but not D3.

This is a use-specific wrapper around #scan



109
110
111
112
113
# File 'lib/dobby/scanner.rb', line 109

def scan_by_target
  scan(defect_filter: DEFECT_FILTER_FIXED,
       flag_filter: FLAG_FILTER_DEFAULT,
       version_filter: VERSION_FILTER_TARGET)
end

#scan_one(package:, defect_filter: DEFECT_FILTER_DEFAULT, flag_filter: FLAG_FILTER_DEFAULT, version_filter: VERSION_FILTER_DEFAULT) ⇒ Object

For a given package, determine which packages affect it, if any.



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/dobby/scanner.rb', line 79

def scan_one(package:,
             defect_filter: DEFECT_FILTER_DEFAULT,
             flag_filter: FLAG_FILTER_DEFAULT,
             version_filter: VERSION_FILTER_DEFAULT)
  res = Hash.new { |h, k| h[k] = [] }
  database.defects_for(package).each do |defect|
    next if defect.filtered?(filter: defect_filter, flag_filter: flag_filter)

    defect.fixed_in.each do |v|
      next if package.filtered?(v, version_filter)

      res[package] << defect
    end
  end
  res
end

#scan_one_by_target(package) ⇒ Object

For a specific package, determine which defects are resolved by upgrading to its' target version.

This is a use-specific wrapper around #scan_one

Parameters:



121
122
123
124
125
126
# File 'lib/dobby/scanner.rb', line 121

def scan_one_by_target(package)
  scan_one(package: package,
           defect_filter: DEFECT_FILTER_FIXED,
           flag_filter: FLAG_FILTER_DEFAULT,
           version_filter: VERSION_FILTER_TARGET)
end