Class: Dependabot::Dependency
- Inherits:
-
Object
- Object
- Dependabot::Dependency
- Defined in:
- lib/dependabot/dependency.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#package_manager ⇒ Object
readonly
Returns the value of attribute package_manager.
-
#previous_requirements ⇒ Object
readonly
Returns the value of attribute previous_requirements.
-
#previous_version ⇒ Object
readonly
Returns the value of attribute previous_version.
-
#requirements ⇒ Object
readonly
Returns the value of attribute requirements.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
- .production_check_for_package_manager(package_manager) ⇒ Object
- .register_production_check(package_manager, production_check) ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object
- #appears_in_lockfile? ⇒ Boolean
- #display_name ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(name:, requirements:, package_manager:, version: nil, previous_version: nil, previous_requirements: nil) ⇒ Dependency
constructor
A new instance of Dependency.
- #production? ⇒ Boolean
- #to_h ⇒ Object
- #top_level? ⇒ Boolean
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
#name ⇒ Object (readonly)
Returns the value of attribute name.
20 21 22 |
# File 'lib/dependabot/dependency.rb', line 20 def name @name end |
#package_manager ⇒ Object (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_requirements ⇒ Object (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_version ⇒ Object (readonly)
Returns the value of attribute previous_version.
20 21 22 |
# File 'lib/dependabot/dependency.rb', line 20 def previous_version @previous_version end |
#requirements ⇒ Object (readonly)
Returns the value of attribute requirements.
20 21 22 |
# File 'lib/dependabot/dependency.rb', line 20 def requirements @requirements end |
#version ⇒ Object (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
51 52 53 |
# File 'lib/dependabot/dependency.rb', line 51 def appears_in_lockfile? previous_version || (version && previous_requirements.nil?) end |
#display_name ⇒ Object
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
79 80 81 |
# File 'lib/dependabot/dependency.rb', line 79 def eql?(other) self.==(other) end |
#hash ⇒ Object
75 76 77 |
# File 'lib/dependabot/dependency.rb', line 75 def hash to_h.hash end |
#production? ⇒ 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_h ⇒ Object
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
36 37 38 |
# File 'lib/dependabot/dependency.rb', line 36 def top_level? requirements.any? end |