Class: HolePicker::Vulnerability

Inherits:
Object
  • Object
show all
Defined in:
lib/holepicker/vulnerability.rb

Constant Summary collapse

NEW_VULNERABILITY_DAYS =
7
NEW_VULNERABILITY_TIME =
NEW_VULNERABILITY_DAYS * 86400

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#dateObject (readonly)

Returns the value of attribute date.



9
10
11
# File 'lib/holepicker/vulnerability.rb', line 9

def date
  @date
end

#gemsObject (readonly)

Returns the value of attribute gems.



9
10
11
# File 'lib/holepicker/vulnerability.rb', line 9

def gems
  @gems
end

#idObject (readonly)

Returns the value of attribute id.



9
10
11
# File 'lib/holepicker/vulnerability.rb', line 9

def id
  @id
end

#noteObject (readonly)

Returns the value of attribute note.



9
10
11
# File 'lib/holepicker/vulnerability.rb', line 9

def note
  @note
end

#urlObject (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_idObject



11
12
13
14
# File 'lib/holepicker/vulnerability.rb', line 11

def self.next_id
  @@count ||= 0
  @@count += 1
end

Instance Method Details

#dayObject



29
30
31
# File 'lib/holepicker/vulnerability.rb', line 29

def day
  @date.strftime("%Y-%m-%d")
end

#gem_namesObject



41
42
43
# File 'lib/holepicker/vulnerability.rb', line 41

def gem_names
  @gems.keys
end

#gem_safe?(gem) ⇒ Boolean

Returns:

  • (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

Returns:

  • (Boolean)


45
46
47
# File 'lib/holepicker/vulnerability.rb', line 45

def gem_vulnerable?(gem)
  !gem_safe?(gem)
end

#recent?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/holepicker/vulnerability.rb', line 33

def recent?
  date > Time.now - NEW_VULNERABILITY_TIME
end

#tagObject



37
38
39
# File 'lib/holepicker/vulnerability.rb', line 37

def tag
  "##{@id}"
end