Class: Friday::Dependency

Inherits:
Object
  • Object
show all
Defined in:
app/models/friday/dependency.rb

Overview

A library/package that is depended on

Defined Under Namespace

Classes: Versioned

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(language, name) ⇒ Dependency

Returns a new instance of Dependency.



149
150
151
152
# File 'app/models/friday/dependency.rb', line 149

def initialize(language, name)
  @language = language
  @name = name
end

Instance Attribute Details

#languageObject (readonly)

Returns the value of attribute language.



147
148
149
# File 'app/models/friday/dependency.rb', line 147

def language
  @language
end

#nameObject (readonly)

Returns the value of attribute name.



147
148
149
# File 'app/models/friday/dependency.rb', line 147

def name
  @name
end

Class Method Details

.allObject



112
113
114
115
116
# File 'app/models/friday/dependency.rb', line 112

def all
  Friday.redis.zrange('dependencies', 0, -1).map do |key|
    from_key(key)
  end
end

.for(dependencies_key) ⇒ Object



118
119
120
121
122
123
124
125
126
# File 'app/models/friday/dependency.rb', line 118

def for(dependencies_key)
  dependencies = Friday.redis.zinter(dependencies_key, 'vulnerabilities', with_scores: true)

  dependencies.map do |key, vulnerability_score|
    dep = Versioned.from_redis(key, vulnerability_score)

    [dep.name, dep]
  end.to_h
end

.from_key(key) ⇒ Object



128
129
130
131
132
133
134
135
136
# File 'app/models/friday/dependency.rb', line 128

def from_key(key)
  language, name, version = parse_key(key)

  if version.nil?
    new(language, name)
  else
    new(language, name).at(version)
  end
end

Instance Method Details

#==(other) ⇒ Object



170
171
172
# File 'app/models/friday/dependency.rb', line 170

def ==(other)
  self.class == other.class && to_s == other.to_s
end

#at(version) ⇒ Object



154
155
156
# File 'app/models/friday/dependency.rb', line 154

def at(version)
  Versioned.new(self, version)
end

#deps_for_language_keyObject



174
175
176
# File 'app/models/friday/dependency.rb', line 174

def deps_for_language_key
  "dependencies:#{language}"
end

#to_sObject



166
167
168
# File 'app/models/friday/dependency.rb', line 166

def to_s
  "#{language}:#{name}"
end

#versionsObject



158
159
160
# File 'app/models/friday/dependency.rb', line 158

def versions
  Friday.redis.zrange(versions_key, 0, -1)
end

#versions_keyObject



178
179
180
# File 'app/models/friday/dependency.rb', line 178

def versions_key
  "#{self}:versions"
end

#with_dependentsObject



162
163
164
# File 'app/models/friday/dependency.rb', line 162

def with_dependents
  as_json.merge!({ versions: versions.index_with { |v| at(v).dependents.map(&:to_i) } })
end