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.



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

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.



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



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

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

#appears_in_lockfile?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/dependabot/dependency.rb', line 73

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

#display_nameObject



87
88
89
90
91
92
93
# File 'lib/dependabot/dependency.rb', line 87

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)


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

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

#hashObject



99
100
101
# File 'lib/dependabot/dependency.rb', line 99

def hash
  to_h.hash
end

#production?Boolean

Returns:

  • (Boolean)


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

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



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/dependabot/dependency.rb', line 61

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)


57
58
59
# File 'lib/dependabot/dependency.rb', line 57

def top_level?
  requirements.any?
end