Class: Friday::Dependency::Versioned
- Inherits:
-
Object
- Object
- Friday::Dependency::Versioned
- Defined in:
- app/models/friday/dependency.rb
Overview
A specific version of a Dependency
Instance Attribute Summary collapse
-
#dependency ⇒ Object
readonly
Returns the value of attribute dependency.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #add_app(id) ⇒ Object
- #dependents ⇒ Object
-
#initialize(dependency, version, vulnerability_status = nil) ⇒ Versioned
constructor
A new instance of Versioned.
- #remove_app(id) ⇒ Object
- #to_hash ⇒ Object
- #to_s ⇒ Object
- #vulnerability_status ⇒ Object
Constructor Details
#initialize(dependency, version, vulnerability_status = nil) ⇒ Versioned
Returns a new instance of Versioned.
28 29 30 31 32 |
# File 'app/models/friday/dependency.rb', line 28 def initialize(dependency, version, vulnerability_status = nil) @dependency = dependency @version = version @vulnerability_status = vulnerability_status end |
Instance Attribute Details
#dependency ⇒ Object (readonly)
Returns the value of attribute dependency.
24 25 26 |
# File 'app/models/friday/dependency.rb', line 24 def dependency @dependency end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
24 25 26 |
# File 'app/models/friday/dependency.rb', line 24 def version @version end |
Class Method Details
.from_redis(key, criticality_score) ⇒ Object
9 10 11 12 13 14 15 |
# File 'app/models/friday/dependency.rb', line 9 def from_redis(key, criticality_score) vulnerability_status = CRITICALITIES[criticality_score] language, name, version = parse_key(key) new(Dependency.new(language, name), version, vulnerability_status) end |
.parse_key(key) ⇒ Object
17 18 19 20 21 |
# File 'app/models/friday/dependency.rb', line 17 def parse_key(key) # I think the dependency name will have to be base64 encoded because java # dependencies appear to have : in the name key.split(':') end |
Instance Method Details
#==(other) ⇒ Object
83 84 85 |
# File 'app/models/friday/dependency.rb', line 83 def ==(other) self.class == other.class && to_s == other.to_s end |
#add_app(id) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'app/models/friday/dependency.rb', line 42 def add_app(id) criticality_score = CRITICALITIES.index(vulnerability_status) Friday.redis.zadd('dependencies', 0, dependency.to_s) Friday.redis.zadd('vulnerabilities', criticality_score, to_s) Friday.redis.zadd(dependency.versions_key, 0, version) Friday.redis.zadd(dependents_key, 0, id.to_s) end |
#dependents ⇒ Object
34 35 36 |
# File 'app/models/friday/dependency.rb', line 34 def dependents Friday.redis.zrange(dependents_key, 0, -1) end |
#remove_app(id) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/models/friday/dependency.rb', line 51 def remove_app(id) script = <<-LUA redis.call("ZREM", KEYS[1], ARGV[1]) if redis.call("EXISTS", KEYS[1]) == 1 then return end redis.call("ZREM", KEYS[2], ARGV[2]) redis.call("ZREM", "vulnerabilities", ARGV[3]) if redis.call("EXISTS", KEYS[2]) == 1 then return end redis.call("ZREM", "dependencies", ARGV[4]) LUA Friday.redis.eval( script, [dependents_key, dependency.versions_key], [id.to_s, version, to_s, dependency.to_s] ) end |
#to_hash ⇒ Object
72 73 74 75 76 77 |
# File 'app/models/friday/dependency.rb', line 72 def to_hash @dependency.as_json.merge!( version: @version, vulnerability_status: @vulnerability_status ) end |
#to_s ⇒ Object
79 80 81 |
# File 'app/models/friday/dependency.rb', line 79 def to_s "#{@dependency}:#{version}" end |
#vulnerability_status ⇒ Object
38 39 40 |
# File 'app/models/friday/dependency.rb', line 38 def vulnerability_status @vulnerability_status ||= CRITICALITIES[criticality_index] end |