Class: CVEList::Repository
- Includes:
- Enumerable
- Defined in:
- lib/cvelist/repository.rb
Constant Summary collapse
- URL =
The default git URI for the cvelist repository
'https://github.com/CVEProject/cvelist.git'
- REMOTE =
The default git remote.
'origin'
- BRANCH =
The default git branch.
'master'
- GLOB =
Dir.glob
for year directories. '[1-2][0-9][0-9][0-9]'
Instance Attribute Summary
Attributes inherited from Directory
Class Method Summary collapse
-
.clone(path, url: URL, depth: 1) ⇒ Object
(also: download)
Clones a new repository.
Instance Method Summary collapse
-
#[](cve_id) ⇒ CVE?
Accesses a CVE from the repository with the given CVE ID.
-
#directories ⇒ Array<String>
The year directories within the repository.
-
#each {|cve| ... } ⇒ Enumerator
Enumerates over every CVE withing the year directories.
-
#each_malformed {|malformed_cve| ... } ⇒ Enumerator
Enumerates over every malformed CVE within the repository.
-
#git? ⇒ Boolean
Determines whether the repository is a git repository.
-
#has_cve?(cve_id) ⇒ Boolean
Determines whether the repository contains the given CVE ID.
-
#has_year?(year) ⇒ Boolean
Determines if the repository contains a directory for the given year.
-
#pull!(remote: REMOTE, branch: BRANCH) ⇒ true, false
(also: #update!)
Pulls down new commits from the given remote/branch.
-
#size ⇒ Integer
Calculates the total number of CVEs in the repository.
-
#year(year_number) ⇒ YearDir
(also: #/)
Requests a year directory from the repository.
-
#years(&block) ⇒ Array<YearDir>
The year directories contained within the repository.
Methods inherited from Directory
#directory?, #file?, #glob, #initialize, #join, #to_s
Constructor Details
This class inherits a constructor from CVEList::Directory
Class Method Details
.clone(path, url: URL, depth: 1) ⇒ Object Also known as: download
Clones a new repository.
30 31 32 33 34 35 36 |
# File 'lib/cvelist/repository.rb', line 30 def self.clone(path, url: URL, depth: 1) unless system 'git', 'clone', '--depth', depth.to_s, url.to_s, path.to_s raise(GitCloneFailed,"failed to clone #{url.inspect} into #{path.inspect}") end return new(path) end |
Instance Method Details
#[](cve_id) ⇒ CVE?
Accesses a CVE from the repository with the given CVE ID.
216 217 218 219 220 221 222 |
# File 'lib/cvelist/repository.rb', line 216 def [](cve_id) year_number = cve_to_year(cve_id) if has_year?(year_number) year(year_number)[cve_id] end end |
#directories ⇒ Array<String>
The year directories within the repository.
110 111 112 |
# File 'lib/cvelist/repository.rb', line 110 def directories glob(GLOB).sort end |
#each {|cve| ... } ⇒ Enumerator
Enumerates over every CVE withing the year directories.
160 161 162 163 164 165 166 |
# File 'lib/cvelist/repository.rb', line 160 def each(&block) return enum_for(__method__) unless block_given? years.each do |year_dir| year_dir.each(&block) end end |
#each_malformed {|malformed_cve| ... } ⇒ Enumerator
Enumerates over every malformed CVE within the repository.
181 182 183 184 185 186 187 |
# File 'lib/cvelist/repository.rb', line 181 def each_malformed(&block) return enum_for(__method__) unless block_given? years.each do |year_dir| year_dir.each_malformed(&block) end end |
#git? ⇒ Boolean
Determines whether the repository is a git repository.
48 49 50 |
# File 'lib/cvelist/repository.rb', line 48 def git? directory?('.git') end |
#has_cve?(cve_id) ⇒ Boolean
Determines whether the repository contains the given CVE ID.
197 198 199 200 201 |
# File 'lib/cvelist/repository.rb', line 197 def has_cve?(cve_id) year_number = cve_to_year(cve_id) return has_year?(year_number) && year(year_number).has_cve?(cve_id) end |
#has_year?(year) ⇒ Boolean
Determines if the repository contains a directory for the given year.
97 98 99 |
# File 'lib/cvelist/repository.rb', line 97 def has_year?(year) directory?(year.to_s) end |
#pull!(remote: REMOTE, branch: BRANCH) ⇒ true, false Also known as: update!
Pulls down new commits from the given remote/branch.
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/cvelist/repository.rb', line 74 def pull!(remote: REMOTE, branch: BRANCH) return false unless git? Dir.chdir(@path) do unless system('git', 'pull', remote.to_s, branch.to_s) raise(GitPullFailed,"failed to pull from remote #{remote.inspect} branch #{branch.inspect}") end end return true end |
#size ⇒ Integer
Calculates the total number of CVEs in the repository.
229 230 231 |
# File 'lib/cvelist/repository.rb', line 229 def size Dir[join(GLOB,YearDir::GLOB,RangeDir::GLOB)].length end |
#year(year_number) ⇒ YearDir Also known as: /
Requests a year directory from the repository.
136 137 138 139 140 141 142 143 144 |
# File 'lib/cvelist/repository.rb', line 136 def year(year_number) year_dir = join(year_number.to_s) unless File.directory?(year_dir) raise(YearDirNotFound,"year #{year_number.inspect} not found within #{@path.inspect}") end return YearDir.new(year_dir) end |