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


42
43
44
45
46
47
48
49
# File 'lib/dependabot/file_parsers/base/dependency_set.rb', line 42

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

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

#<<(dep) ⇒ Object


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

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

  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