Class: Dependabot::Maven::FileUpdater::PropertyValueUpdater
- Inherits:
-
Object
- Object
- Dependabot::Maven::FileUpdater::PropertyValueUpdater
- Defined in:
- lib/dependabot/maven/file_updater/property_value_updater.rb
Instance Method Summary collapse
-
#initialize(dependency_files:) ⇒ PropertyValueUpdater
constructor
A new instance of PropertyValueUpdater.
- #update_pomfiles_for_property_change(property_name:, callsite_pom:, updated_value:) ⇒ Object
Constructor Details
#initialize(dependency_files:) ⇒ PropertyValueUpdater
Returns a new instance of PropertyValueUpdater.
13 14 15 |
# File 'lib/dependabot/maven/file_updater/property_value_updater.rb', line 13 def initialize(dependency_files:) @dependency_files = dependency_files end |
Instance Method Details
#update_pomfiles_for_property_change(property_name:, callsite_pom:, updated_value:) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/dependabot/maven/file_updater/property_value_updater.rb', line 17 def update_pomfiles_for_property_change(property_name:, callsite_pom:, updated_value:) declaration_details = property_value_finder.property_details( property_name: property_name, callsite_pom: callsite_pom ) node = declaration_details.fetch(:node) filename = declaration_details.fetch(:file) pom_to_update = dependency_files.find { |f| f.name == filename } property_re = %r{<#{Regexp.quote(node.name)}> \s*#{Regexp.quote(node.content)}\s* </#{Regexp.quote(node.name)}>}xm property_text = node.to_s if pom_to_update.content =~ property_re updated_content = pom_to_update.content.sub( property_re, "<#{node.name}>#{updated_value}</#{node.name}>" ) elsif pom_to_update.content.include? property_text node.content = updated_value updated_content = pom_to_update.content.sub( property_text, node.to_s ) end updated_pomfiles = dependency_files.dup updated_pomfiles[updated_pomfiles.index(pom_to_update)] = update_file(file: pom_to_update, content: updated_content) updated_pomfiles end |