Class: Dependabot::FileParsers::Base::DependencySet

Inherits:
Object
  • Object
show all
Defined in:
lib/dependabot/file_parsers/base/dependency_set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dependencies = [], case_sensitive: false) ⇒ DependencySet

Returns a new instance of DependencySet.



11
12
13
14
15
16
17
18
19
# File 'lib/dependabot/file_parsers/base/dependency_set.rb', line 11

def initialize(dependencies = [], case_sensitive: false)
  unless dependencies.is_a?(Array) &&
         dependencies.all? { |dep| dep.is_a?(Dependency) }
    raise ArgumentError, "must be an array of Dependency objects"
  end

  @dependencies = dependencies
  @case_sensitive = case_sensitive
end

Instance Attribute Details

#dependenciesObject (readonly)

Returns the value of attribute dependencies.



21
22
23
# File 'lib/dependabot/file_parsers/base/dependency_set.rb', line 21

def dependencies
  @dependencies
end

Instance Method Details

#+(other) ⇒ Object

Raises:

  • (ArgumentError)


40
41
42
43
44
45
# File 'lib/dependabot/file_parsers/base/dependency_set.rb', line 40

def +(other)
  raise ArgumentError, "must be a DependencySet" unless other.is_a?(DependencySet)

  other.dependencies.each { |dep| self << dep }
  self
end

#<<(dep) ⇒ Object

Raises:

  • (ArgumentError)


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/dependabot/file_parsers/base/dependency_set.rb', line 23

def <<(dep)
  raise ArgumentError, "must be a Dependency object" unless dep.is_a?(Dependency)

  existing_dependency = dependency_for_name(dep.name)

  return self if existing_dependency&.to_h == dep.to_h

  if existing_dependency
    dependencies[dependencies.index(existing_dependency)] =
      combined_dependency(existing_dependency, dep)
  else
    dependencies << dep
  end

  self
end