Class: Dependabot::Maven::Shared::SharedPropertyValueUpdater
- Inherits:
-
Object
- Object
- Dependabot::Maven::Shared::SharedPropertyValueUpdater
- Extended by:
- T::Helpers, T::Sig
- Defined in:
- lib/dependabot/maven/shared/shared_property_value_updater.rb
Overview
Shared base for text-based property value updaters (Gradle, SBT). Subclasses must override ‘property_value_finder` to return the ecosystem-specific PropertyValueFinder instance.
Maven’s PropertyValueUpdater is XML-based and does not share this class.
Instance Method Summary collapse
-
#initialize(dependency_files:) ⇒ SharedPropertyValueUpdater
constructor
A new instance of SharedPropertyValueUpdater.
- #update_files_for_property_change(property_name:, callsite_buildfile:, previous_value:, updated_value:) ⇒ Object
Constructor Details
#initialize(dependency_files:) ⇒ SharedPropertyValueUpdater
Returns a new instance of SharedPropertyValueUpdater.
22 23 24 |
# File 'lib/dependabot/maven/shared/shared_property_value_updater.rb', line 22 def initialize(dependency_files:) @dependency_files = T.let(dependency_files, T::Array[DependencyFile]) end |
Instance Method Details
#update_files_for_property_change(property_name:, callsite_buildfile:, previous_value:, updated_value:) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/dependabot/maven/shared/shared_property_value_updater.rb', line 34 def update_files_for_property_change( property_name:, callsite_buildfile:, previous_value:, updated_value: ) declaration_details = property_value_finder.property_details( property_name: property_name, callsite_buildfile: callsite_buildfile ) raise "Property '#{property_name}' not found" unless declaration_details declaration_string = T.let(declaration_details.fetch(:declaration_string), String) filename = T.let(declaration_details.fetch(:file), String) file_to_update = T.must(dependency_files.find { |f| f.name == filename }) updated_content = T.must(file_to_update.content).sub( declaration_string, declaration_string.sub( previous_value_regex(previous_value), updated_value ) ) updated_files = dependency_files.dup updated_files[T.must(updated_files.index(file_to_update))] = update_file(file: file_to_update, content: updated_content) updated_files end |