Class: Dependabot::Gradle::FileUpdater::PropertyValueUpdater
- Inherits:
-
Object
- Object
- Dependabot::Gradle::FileUpdater::PropertyValueUpdater
- Defined in:
- lib/dependabot/gradle/file_updater/property_value_updater.rb
Instance Method Summary collapse
-
#initialize(dependency_files:) ⇒ PropertyValueUpdater
constructor
A new instance of PropertyValueUpdater.
- #update_files_for_property_change(property_name:, callsite_buildfile:, previous_value:, updated_value:) ⇒ Object
Constructor Details
#initialize(dependency_files:) ⇒ PropertyValueUpdater
Returns a new instance of PropertyValueUpdater.
10 11 12 |
# File 'lib/dependabot/gradle/file_updater/property_value_updater.rb', line 10 def initialize(dependency_files:) @dependency_files = dependency_files end |
Instance Method Details
#update_files_for_property_change(property_name:, callsite_buildfile:, previous_value:, updated_value:) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/dependabot/gradle/file_updater/property_value_updater.rb', line 14 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 ) declaration_string = declaration_details.fetch(:declaration_string) filename = declaration_details.fetch(:file) file_to_update = dependency_files.find { |f| f.name == filename } updated_content = file_to_update.content.sub( declaration_string, declaration_string.sub( previous_value_regex(previous_value), updated_value ) ) updated_files = dependency_files.dup updated_files[updated_files.index(file_to_update)] = update_file(file: file_to_update, content: updated_content) updated_files end |