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, subdependency_metadata: nil) ⇒ Dependency

Returns a new instance of Dependency.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/dependabot/dependency.rb', line 33

def initialize(name:, requirements:, package_manager:, version: nil,
               previous_version: nil, previous_requirements: nil,
               subdependency_metadata: 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
  @subdependency_metadata =  unless top_level?

  check_values
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



29
30
31
# File 'lib/dependabot/dependency.rb', line 29

def name
  @name
end

#package_managerObject (readonly)

Returns the value of attribute package_manager.



29
30
31
# File 'lib/dependabot/dependency.rb', line 29

def package_manager
  @package_manager
end

#previous_requirementsObject (readonly)

Returns the value of attribute previous_requirements.



29
30
31
# File 'lib/dependabot/dependency.rb', line 29

def previous_requirements
  @previous_requirements
end

#previous_versionObject (readonly)

Returns the value of attribute previous_version.



29
30
31
# File 'lib/dependabot/dependency.rb', line 29

def previous_version
  @previous_version
end

#requirementsObject (readonly)

Returns the value of attribute requirements.



29
30
31
# File 'lib/dependabot/dependency.rb', line 29

def requirements
  @requirements
end

#subdependency_metadataObject (readonly)

Returns the value of attribute subdependency_metadata.



29
30
31
# File 'lib/dependabot/dependency.rb', line 29

def 
  @subdependency_metadata
end

#versionObject (readonly)

Returns the value of attribute version.



29
30
31
# File 'lib/dependabot/dependency.rb', line 29

def version
  @version
end

Class Method Details

.display_name_builder_for_package_manager(package_manager) ⇒ Object



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

def self.display_name_builder_for_package_manager(package_manager)
  @display_name_builders[package_manager]
end

.production_check_for_package_manager(package_manager) ⇒ Object



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

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_display_name_builder(package_manager, name_builder) ⇒ Object



25
26
27
# File 'lib/dependabot/dependency.rb', line 25

def self.register_display_name_builder(package_manager, name_builder)
  @display_name_builders[package_manager] = name_builder
end

.register_production_check(package_manager, production_check) ⇒ Object



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

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

Instance Method Details

#==(other) ⇒ Object



86
87
88
# File 'lib/dependabot/dependency.rb', line 86

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

#appears_in_lockfile?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/dependabot/dependency.rb', line 64

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

#display_nameObject



78
79
80
81
82
83
84
# File 'lib/dependabot/dependency.rb', line 78

def display_name
  display_name_builder =
    self.class.display_name_builder_for_package_manager(package_manager)
  return name unless display_name_builder

  display_name_builder.call(name)
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/dependabot/dependency.rb', line 94

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

#hashObject



90
91
92
# File 'lib/dependabot/dependency.rb', line 90

def hash
  to_h.hash
end

#production?Boolean

Returns:

  • (Boolean)


68
69
70
71
72
73
74
75
76
# File 'lib/dependabot/dependency.rb', line 68

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



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

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

#top_level?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/dependabot/dependency.rb', line 48

def top_level?
  requirements.any?
end