Class: Bundler::Plumber::Database
- Inherits:
-
Object
- Object
- Bundler::Plumber::Database
- Defined in:
- lib/bundler/plumber/database.rb
Overview
Represents the directory of advisories, grouped by gem name and CVE number.
Constant Summary collapse
- URL =
Git URL of the ruby-mem-advisory-db
'https://github.com/rubymem/ruby-mem-advisory-db.git'
- VENDORED_PATH =
Default path to the ruby-mem-advisory-db
File.(File.join(File.dirname(__FILE__),'..','..','..','data','ruby-mem-advisory-db'))
- VENDORED_TIMESTAMP =
Timestamp for when the database was last updated
Time.parse(File.read("#{VENDORED_PATH}.ts")).utc
- USER_PATH =
Path to the user's copy of the ruby-mem-advisory-db
File.(File.join(ENV['HOME'],'.local','share','ruby-mem-advisory-db'))
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
The path to the advisory database.
Class Method Summary collapse
-
.path ⇒ String
The default path for the database.
-
.update!(options = {}) ⇒ Boolean?
Updates the ruby-mem-advisory-db.
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 = self.class.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 = self.class.path) ⇒ Database
Initializes the Advisory Database.
56 57 58 59 60 61 62 |
# File 'lib/bundler/plumber/database.rb', line 56 def initialize(path=self.class.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
45 46 47 |
# File 'lib/bundler/plumber/database.rb', line 45 def path @path end |
Class Method Details
.path ⇒ String
The default path for the database.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/bundler/plumber/database.rb', line 70 def self.path if File.directory?(USER_PATH) t1 = Dir.chdir(USER_PATH) { Time.parse(`git log --date=iso8601 --pretty="%cd" -1`) } t2 = VENDORED_TIMESTAMP if t1 >= t2 USER_PATH else VENDORED_PATH end else VENDORED_PATH end end |
.update!(options = {}) ⇒ Boolean?
Requires network access.
Updates the ruby-mem-advisory-db.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/bundler/plumber/database.rb', line 98 def self.update!(={}) raise "Invalid option(s)" unless (.keys - [:quiet]).empty? if File.directory?(USER_PATH) if File.directory?(File.join(USER_PATH, ".git")) Dir.chdir(USER_PATH) do command = "git fetch --all; git reset --hard origin/main" command << ' --quiet' if [:quiet] system *command end end else command = %w(git clone) command << '--quiet' if [:quiet] command << URL << USER_PATH system *command end end |
Instance Method Details
#advisories {|advisory| ... } ⇒ Enumerator
Enumerates over every advisory in the database.
129 130 131 132 133 134 135 |
# File 'lib/bundler/plumber/database.rb', line 129 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.
152 153 154 155 156 157 158 |
# File 'lib/bundler/plumber/database.rb', line 152 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.
176 177 178 179 180 181 182 183 184 |
# File 'lib/bundler/plumber/database.rb', line 176 def check_gem(gem) return enum_for(__method__,gem) unless block_given? advisories_for(gem.name) do |advisory| if advisory.leaky?(gem.version) yield advisory end end end |
#each_advisory_path {|path| ... } ⇒ Object (protected)
Enumerates over every advisory path in the database.
227 228 229 |
# File 'lib/bundler/plumber/database.rb', line 227 def each_advisory_path(&block) Dir.glob(File.join(@path,'gems','*','*.yml'),&block) end |
#each_advisory_path_for(name) {|path| ... } ⇒ Object (protected)
Enumerates over the advisories for the given gem.
243 244 245 |
# File 'lib/bundler/plumber/database.rb', line 243 def each_advisory_path_for(name,&block) Dir.glob(File.join(@path,'gems',name,'*.yml'),&block) end |
#inspect ⇒ String
Inspects the database.
212 213 214 |
# File 'lib/bundler/plumber/database.rb', line 212 def inspect "#<#{self.class}:#{self}>" end |
#size ⇒ Integer
The number of advisories within the database.
192 193 194 |
# File 'lib/bundler/plumber/database.rb', line 192 def size each_advisory_path.count end |
#to_s ⇒ String
Converts the database to a String.
202 203 204 |
# File 'lib/bundler/plumber/database.rb', line 202 def to_s @path end |