Class: Bundler::Audit::Database
- Inherits:
-
Object
- Object
- Bundler::Audit::Database
- Defined in:
- lib/bundler/audit/database.rb
Overview
Represents the directory of advisories, grouped by gem name and CVE number.
Constant Summary collapse
- PATH =
directory containing advisories
File.(File.join(File.dirname(__FILE__),'..','..','..','data','ruby-advisory-db','gems'))
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
The path to the advisory database.
Instance Method Summary collapse
-
#advisories {|advisory| ... } ⇒ Enumerator
Enumerates over every advisory in the database.
-
#advisories_for(name) {|advisory| ... } ⇒ Enumerator
Enumerates over advisories for the given gem.
-
#check_gem(gem) {|advisory| ... } ⇒ Enumerator
Verifies whether the gem is effected by any advisories.
-
#each_advisory_path {|path| ... } ⇒ Object
protected
Enumerates over every advisory path in the database.
-
#each_advisory_path_for(name) {|path| ... } ⇒ Object
protected
Enumerates over the advisories for the given gem.
-
#initialize(path = PATH) ⇒ Database
constructor
Initializes the Advisory Database.
-
#inspect ⇒ String
Inspects the database.
-
#size ⇒ Integer
The number of advisories within the database.
-
#to_s ⇒ String
Converts the database to a String.
Constructor Details
#initialize(path = PATH) ⇒ Database
Initializes the Advisory Database.
47 48 49 50 51 52 53 |
# File 'lib/bundler/audit/database.rb', line 47 def initialize(path=PATH) unless File.directory?(path) raise(ArgumentError,"#{path.dump} is not a directory") end @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
The path to the advisory database
36 37 38 |
# File 'lib/bundler/audit/database.rb', line 36 def path @path end |
Instance Method Details
#advisories {|advisory| ... } ⇒ Enumerator
Enumerates over every advisory in the database.
67 68 69 70 71 72 73 |
# File 'lib/bundler/audit/database.rb', line 67 def advisories(&block) return enum_for(__method__) unless block_given? each_advisory_path do |path| yield Advisory.load(path) end end |
#advisories_for(name) {|advisory| ... } ⇒ Enumerator
Enumerates over advisories for the given gem.
90 91 92 93 94 95 96 |
# File 'lib/bundler/audit/database.rb', line 90 def advisories_for(name) return enum_for(__method__,name) unless block_given? each_advisory_path_for(name) do |path| yield Advisory.load(path) end end |
#check_gem(gem) {|advisory| ... } ⇒ Enumerator
Verifies whether the gem is effected by any advisories.
114 115 116 117 118 119 120 121 122 |
# File 'lib/bundler/audit/database.rb', line 114 def check_gem(gem) return enum_for(__method__,gem) unless block_given? advisories_for(gem.name) do |advisory| if advisory.vulnerable?(gem.version) yield advisory end end end |
#each_advisory_path {|path| ... } ⇒ Object (protected)
Enumerates over every advisory path in the database.
165 166 167 |
# File 'lib/bundler/audit/database.rb', line 165 def each_advisory_path(&block) Dir.glob(File.join(@path,'*','*.yml'),&block) end |
#each_advisory_path_for(name) {|path| ... } ⇒ Object (protected)
Enumerates over the advisories for the given gem.
181 182 183 |
# File 'lib/bundler/audit/database.rb', line 181 def each_advisory_path_for(name,&block) Dir.glob(File.join(@path,name,'*.yml'),&block) end |
#inspect ⇒ String
Inspects the database.
150 151 152 |
# File 'lib/bundler/audit/database.rb', line 150 def inspect "#<#{self.class}:#{self}>" end |
#size ⇒ Integer
The number of advisories within the database.
130 131 132 |
# File 'lib/bundler/audit/database.rb', line 130 def size each_advisory_path.count end |
#to_s ⇒ String
Converts the database to a String.
140 141 142 |
# File 'lib/bundler/audit/database.rb', line 140 def to_s @path end |