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: []) ⇒ Dependency

Returns a new instance of Dependency.


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/dependabot/dependency.rb', line 42

def initialize(name:, requirements:, package_manager:, version: nil,
               previous_version: nil, previous_requirements: nil,
               subdependency_metadata: [])
  @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
  unless top_level? ||  == []
    @subdependency_metadata = &.
                              map { |h| symbolize_keys(h) }
  end

  check_values
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


38
39
40
# File 'lib/dependabot/dependency.rb', line 38

def name
  @name
end

#package_managerObject (readonly)

Returns the value of attribute package_manager


38
39
40
# File 'lib/dependabot/dependency.rb', line 38

def package_manager
  @package_manager
end

#previous_requirementsObject (readonly)

Returns the value of attribute previous_requirements


38
39
40
# File 'lib/dependabot/dependency.rb', line 38

def previous_requirements
  @previous_requirements
end

#previous_versionObject (readonly)

Returns the value of attribute previous_version


38
39
40
# File 'lib/dependabot/dependency.rb', line 38

def previous_version
  @previous_version
end

#requirementsObject (readonly)

Returns the value of attribute requirements


38
39
40
# File 'lib/dependabot/dependency.rb', line 38

def requirements
  @requirements
end

#subdependency_metadataObject (readonly)

Returns the value of attribute subdependency_metadata


38
39
40
# File 'lib/dependabot/dependency.rb', line 38

def 
  @subdependency_metadata
end

#versionObject (readonly)

Returns the value of attribute version


38
39
40
# File 'lib/dependabot/dependency.rb', line 38

def version
  @version
end

Class Method Details

.display_name_builder_for_package_manager(package_manager) ⇒ Object


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

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

.name_normaliser_for_package_manager(package_manager) ⇒ Object


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

def self.name_normaliser_for_package_manager(package_manager)
  @name_normalisers[package_manager] || ->(name) { name }
end

.production_check_for_package_manager(package_manager) ⇒ Object


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

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


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

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

.register_name_normaliser(package_manager, name_builder) ⇒ Object


34
35
36
# File 'lib/dependabot/dependency.rb', line 34

def self.register_name_normaliser(package_manager, name_builder)
  @name_normalisers[package_manager] = name_builder
end

.register_production_check(package_manager, production_check) ⇒ Object


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

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

Instance Method Details

#==(other) ⇒ Object


102
103
104
# File 'lib/dependabot/dependency.rb', line 102

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

#appears_in_lockfile?Boolean

Returns:

  • (Boolean)

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

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

#display_nameObject


94
95
96
97
98
99
100
# File 'lib/dependabot/dependency.rb', line 94

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)

110
111
112
# File 'lib/dependabot/dependency.rb', line 110

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

#hashObject


106
107
108
# File 'lib/dependabot/dependency.rb', line 106

def hash
  to_h.hash
end

#production?Boolean

Returns:

  • (Boolean)

80
81
82
83
84
85
86
87
88
# File 'lib/dependabot/dependency.rb', line 80

def production?
  return subdependency_production_check 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

#subdependency_production_checkObject


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

def subdependency_production_check
  !&.all? { |h| h[:production] == false }
end

#to_hObject


64
65
66
67
68
69
70
71
72
73
74
# File 'lib/dependabot/dependency.rb', line 64

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)

60
61
62
# File 'lib/dependabot/dependency.rb', line 60

def top_level?
  requirements.any?
end