Class: Dependabot::FileParsers::Base::DependencySet
- Inherits:
-
Object
- Object
- Dependabot::FileParsers::Base::DependencySet
- Defined in:
- lib/dependabot/file_parsers/base/dependency_set.rb
Instance Method Summary collapse
- #+(other) ⇒ Object
- #<<(dep) ⇒ Object
- #all_versions_for_name(name) ⇒ Object
- #dependencies ⇒ Object
- #dependency_for_name(name) ⇒ Object
-
#initialize(dependencies = [], case_sensitive: false) ⇒ DependencySet
constructor
A new instance of DependencySet.
Constructor Details
#initialize(dependencies = [], case_sensitive: false) ⇒ DependencySet
Returns a new instance of DependencySet.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/dependabot/file_parsers/base/dependency_set.rb', line 12 def initialize(dependencies = [], case_sensitive: false) unless dependencies.is_a?(Array) && dependencies.all?(Dependency) raise ArgumentError, "must be an array of Dependency objects" end @case_sensitive = case_sensitive @dependencies = Hash.new { |hsh, key| hsh[key] = DependencySlot.new } dependencies.each { |dep| self << dep } end |
Instance Method Details
#+(other) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/dependabot/file_parsers/base/dependency_set.rb', line 34 def +(other) raise ArgumentError, "must be a DependencySet" unless other.is_a?(DependencySet) other_names = other.dependencies.map(&:name) other_names.each do |name| all_versions = other.all_versions_for_name(name) all_versions.each { |dep| self << dep } end self end |
#<<(dep) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/dependabot/file_parsers/base/dependency_set.rb', line 27 def <<(dep) raise ArgumentError, "must be a Dependency object" unless dep.is_a?(Dependency) @dependencies[key_for_dependency(dep)] << dep self end |
#all_versions_for_name(name) ⇒ Object
46 47 48 49 |
# File 'lib/dependabot/file_parsers/base/dependency_set.rb', line 46 def all_versions_for_name(name) key = key_for_name(name) @dependencies.key?(key) ? @dependencies[key].all_versions : [] end |
#dependencies ⇒ Object
23 24 25 |
# File 'lib/dependabot/file_parsers/base/dependency_set.rb', line 23 def dependencies @dependencies.values.filter_map(&:combined) end |
#dependency_for_name(name) ⇒ Object
51 52 53 54 |
# File 'lib/dependabot/file_parsers/base/dependency_set.rb', line 51 def dependency_for_name(name) key = key_for_name(name) @dependencies.key?(key) ? @dependencies[key].combined : nil end |