Class: Bundler::Audit::Scanner
- Inherits:
-
Object
- Object
- Bundler::Audit::Scanner
- Defined in:
- lib/bundler/audit/scanner.rb
Defined Under Namespace
Classes: InsecureSource, UnpatchedGem
Instance Attribute Summary collapse
-
#database ⇒ Database
readonly
The advisory database.
-
#lockfile ⇒ Bundler::LockfileParser
readonly
The parsed
Gemfile.lock
from the project. -
#root ⇒ Object
readonly
Project root directory.
Instance Method Summary collapse
- #get_insecure_sources ⇒ Object protected
- #get_unpatched_gems(ignore) ⇒ Object protected
-
#initialize(root = Dir.pwd) ⇒ Scanner
constructor
Initializes a scanner.
-
#scan(options = {}) {|result| ... } ⇒ Enumerator
Scans the project for issues.
Constructor Details
Instance Attribute Details
#database ⇒ Database (readonly)
The advisory database
20 21 22 |
# File 'lib/bundler/audit/scanner.rb', line 20 def database @database end |
#lockfile ⇒ Bundler::LockfileParser (readonly)
The parsed Gemfile.lock
from the project
28 29 30 |
# File 'lib/bundler/audit/scanner.rb', line 28 def lockfile @lockfile end |
#root ⇒ Object (readonly)
Project root directory
23 24 25 |
# File 'lib/bundler/audit/scanner.rb', line 23 def root @root end |
Instance Method Details
#get_insecure_sources ⇒ Object (protected)
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/bundler/audit/scanner.rb', line 73 def get_insecure_sources insecure = [] @lockfile.sources.each do |source| case source when Source::Git next unless(source.uri =~ /^(git|http):/) insecure << InsecureSource.new(source.uri) when Source::Rubygems source.remotes.map do |uri| next unless uri.scheme == 'http' insecure << InsecureSource.new(uri.to_s) end end end return insecure end |
#get_unpatched_gems(ignore) ⇒ Object (protected)
93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/bundler/audit/scanner.rb', line 93 def get_unpatched_gems(ignore) ignore = Set.new(ignore) # If ignore is empty the Set will contain nil, # but since we should never have a nil version # that's a non-issue. unpatched = [] @lockfile.specs.each do |gem| @database.check_gem(gem) do |advisory| next if ignore.include?(advisory.id) unpatched << UnpatchedGem.new(gem,advisory) end end return unpatched end |
#scan(options = {}) {|result| ... } ⇒ Enumerator
Scans the project for issues.
62 63 64 65 66 67 68 69 |
# File 'lib/bundler/audit/scanner.rb', line 62 def scan(={}) return enum_for(__method__,) unless block_given? get_insecure_sources.each { |source| yield source } get_unpatched_gems([:ignore]).each { |gem| yield gem } return self end |