Class: Dependabot::FileParsers::Base::DependencySet
- Inherits:
-
Object
- Object
- Dependabot::FileParsers::Base::DependencySet
- Extended by:
- T::Sig
- 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.
22 23 24 25 26 27 28 29 |
# File 'lib/dependabot/file_parsers/base/dependency_set.rb', line 22 def initialize(dependencies = [], case_sensitive: false) @case_sensitive = case_sensitive @dependencies = T.let( Hash.new { |hsh, key| hsh[key] = DependencySlot.new }, T::Hash[String, DependencySlot] ) dependencies.each { |dep| self << dep } end |
Instance Method Details
#+(other) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/dependabot/file_parsers/base/dependency_set.rb', line 43 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
37 38 39 40 |
# File 'lib/dependabot/file_parsers/base/dependency_set.rb', line 37 def <<(dep) T.must(@dependencies[key_for_dependency(dep)]) << dep self end |
#all_versions_for_name(name) ⇒ Object
56 57 58 59 |
# File 'lib/dependabot/file_parsers/base/dependency_set.rb', line 56 def all_versions_for_name(name) key = key_for_name(name) @dependencies.key?(key) ? T.must(@dependencies[key]).all_versions : [] end |
#dependencies ⇒ Object
32 33 34 |
# File 'lib/dependabot/file_parsers/base/dependency_set.rb', line 32 def dependencies @dependencies.values.filter_map(&:combined) end |
#dependency_for_name(name) ⇒ Object
62 63 64 65 |
# File 'lib/dependabot/file_parsers/base/dependency_set.rb', line 62 def dependency_for_name(name) key = key_for_name(name) @dependencies.key?(key) ? T.must(@dependencies[key]).combined : nil end |