Class: Dependabot::Dependency

Inherits:
Object
  • Object
show all
Defined in:
lib/dependabot/dependency.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, requirements:, package_manager:, version: nil, previous_version: nil, previous_requirements: nil) ⇒ Dependency

Returns a new instance of Dependency.



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/dependabot/dependency.rb', line 23

def initialize(name:, requirements:, package_manager:, version: nil,
               previous_version: nil, previous_requirements: nil)
  @name = name
  @version = version
  @requirements = requirements.map { |req| symbolize_keys(req) }
  @previous_version = previous_version
  @previous_requirements =
    previous_requirements&.map { |req| symbolize_keys(req) }
  @package_manager = package_manager

  check_values
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



20
21
22
# File 'lib/dependabot/dependency.rb', line 20

def name
  @name
end

#package_managerObject (readonly)

Returns the value of attribute package_manager.



20
21
22
# File 'lib/dependabot/dependency.rb', line 20

def package_manager
  @package_manager
end

#previous_requirementsObject (readonly)

Returns the value of attribute previous_requirements.



20
21
22
# File 'lib/dependabot/dependency.rb', line 20

def previous_requirements
  @previous_requirements
end

#previous_versionObject (readonly)

Returns the value of attribute previous_version.



20
21
22
# File 'lib/dependabot/dependency.rb', line 20

def previous_version
  @previous_version
end

#requirementsObject (readonly)

Returns the value of attribute requirements.



20
21
22
# File 'lib/dependabot/dependency.rb', line 20

def requirements
  @requirements
end

#versionObject (readonly)

Returns the value of attribute version.



20
21
22
# File 'lib/dependabot/dependency.rb', line 20

def version
  @version
end

Class Method Details

.production_check_for_package_manager(package_manager) ⇒ Object



9
10
11
12
13
14
# File 'lib/dependabot/dependency.rb', line 9

def self.production_check_for_package_manager(package_manager)
  production_check = @production_checks[package_manager]
  return production_check if production_check

  raise "Unsupported package_manager #{package_manager}"
end

.register_production_check(package_manager, production_check) ⇒ Object



16
17
18
# File 'lib/dependabot/dependency.rb', line 16

def self.register_production_check(package_manager, production_check)
  @production_checks[package_manager] = production_check
end

Instance Method Details

#==(other) ⇒ Object



71
72
73
# File 'lib/dependabot/dependency.rb', line 71

def ==(other)
  other.instance_of?(self.class) && to_h == other.to_h
end

#appears_in_lockfile?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/dependabot/dependency.rb', line 51

def appears_in_lockfile?
  previous_version || (version && previous_requirements.nil?)
end

#display_nameObject



65
66
67
68
69
# File 'lib/dependabot/dependency.rb', line 65

def display_name
  return name unless %w(maven gradle).include?(package_manager)

  name.split(":").last
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/dependabot/dependency.rb', line 79

def eql?(other)
  self.==(other)
end

#hashObject



75
76
77
# File 'lib/dependabot/dependency.rb', line 75

def hash
  to_h.hash
end

#production?Boolean

Returns:

  • (Boolean)


55
56
57
58
59
60
61
62
63
# File 'lib/dependabot/dependency.rb', line 55

def production?
  return true unless top_level?

  groups = requirements.flat_map { |r| r.fetch(:groups).map(&:to_s) }

  self.class.
    production_check_for_package_manager(package_manager).
    call(groups)
end

#to_hObject



40
41
42
43
44
45
46
47
48
49
# File 'lib/dependabot/dependency.rb', line 40

def to_h
  {
    "name" => name,
    "version" => version,
    "requirements" => requirements,
    "previous_version" => previous_version,
    "previous_requirements" => previous_requirements,
    "package_manager" => package_manager
  }
end

#top_level?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/dependabot/dependency.rb', line 36

def top_level?
  requirements.any?
end