Class: HolePicker::Vulnerability
- Inherits:
-
Object
- Object
- HolePicker::Vulnerability
- Defined in:
- lib/holepicker/vulnerability.rb
Constant Summary collapse
- NEW_VULNERABILITY_DAYS =
7- NEW_VULNERABILITY_TIME =
NEW_VULNERABILITY_DAYS * 86400
Instance Attribute Summary collapse
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#gems ⇒ Object
readonly
Returns the value of attribute gems.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#note ⇒ Object
readonly
Returns the value of attribute note.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #day ⇒ Object
- #gem_names ⇒ Object
- #gem_safe?(gem) ⇒ Boolean
- #gem_vulnerable?(gem) ⇒ Boolean
-
#initialize(json) ⇒ Vulnerability
constructor
A new instance of Vulnerability.
- #recent? ⇒ Boolean
- #tag ⇒ Object
Constructor Details
#initialize(json) ⇒ Vulnerability
Returns a new instance of Vulnerability.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/holepicker/vulnerability.rb', line 16 def initialize(json) @gems = {} json['gems'].each do |name, versions| @gems[name] = versions.map { |v| ::Gem::Version.new(v) } end @id = self.class.next_id @url = json['url'] @note = json['note'] @date = Time.parse(json['date']) end |
Instance Attribute Details
#date ⇒ Object (readonly)
Returns the value of attribute date.
9 10 11 |
# File 'lib/holepicker/vulnerability.rb', line 9 def date @date end |
#gems ⇒ Object (readonly)
Returns the value of attribute gems.
9 10 11 |
# File 'lib/holepicker/vulnerability.rb', line 9 def gems @gems end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/holepicker/vulnerability.rb', line 9 def id @id end |
#note ⇒ Object (readonly)
Returns the value of attribute note.
9 10 11 |
# File 'lib/holepicker/vulnerability.rb', line 9 def note @note end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
9 10 11 |
# File 'lib/holepicker/vulnerability.rb', line 9 def url @url end |
Class Method Details
.next_id ⇒ Object
11 12 13 14 |
# File 'lib/holepicker/vulnerability.rb', line 11 def self.next_id @@count ||= 0 @@count += 1 end |
Instance Method Details
#day ⇒ Object
29 30 31 |
# File 'lib/holepicker/vulnerability.rb', line 29 def day @date.strftime("%Y-%m-%d") end |
#gem_names ⇒ Object
41 42 43 |
# File 'lib/holepicker/vulnerability.rb', line 41 def gem_names @gems.keys end |
#gem_safe?(gem) ⇒ Boolean
49 50 51 52 |
# File 'lib/holepicker/vulnerability.rb', line 49 def gem_safe?(gem) fixes = @gems[gem.name] !fixes || fixes.any? { |fix| fix_included?(fix, gem) } || fixes.all? { |fix| gem.version > fix } end |
#gem_vulnerable?(gem) ⇒ Boolean
45 46 47 |
# File 'lib/holepicker/vulnerability.rb', line 45 def gem_vulnerable?(gem) !gem_safe?(gem) end |
#recent? ⇒ Boolean
33 34 35 |
# File 'lib/holepicker/vulnerability.rb', line 33 def recent? date > Time.now - NEW_VULNERABILITY_TIME end |
#tag ⇒ Object
37 38 39 |
# File 'lib/holepicker/vulnerability.rb', line 37 def tag "##{@id}" end |