Class: Dobby::Scanner
- Inherits:
-
Object
- Object
- Dobby::Scanner
- 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
-
#database ⇒ Object
readonly
Returns the value of attribute database.
-
#packages ⇒ Object
Returns the value of attribute packages.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
Instance Method Summary collapse
-
#initialize(packages, database) ⇒ Scanner
constructor
A new instance of Scanner.
-
#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.
-
#scan_by_target ⇒ Object
Determine which defects are resolved by upgrading to a target version.
-
#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.
-
#scan_one_by_target(package) ⇒ Object
For a specific package, determine which defects are resolved by upgrading to its' target version.
Constructor Details
#initialize(packages, database) ⇒ Scanner
Returns a new instance of Scanner.
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
#database ⇒ Object (readonly)
Returns the value of attribute database.
7 8 9 |
# File 'lib/dobby/scanner.rb', line 7 def database @database end |
#packages ⇒ Object
Returns the value of attribute packages.
7 8 9 |
# File 'lib/dobby/scanner.rb', line 7 def packages @packages end |
#results ⇒ Object (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:
- Flag
- Defect
- Version
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_target ⇒ Object
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
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 |