Class: Dependabot::Nuget::FileUpdater::PropertyValueUpdater
- Inherits:
-
Object
- Object
- Dependabot::Nuget::FileUpdater::PropertyValueUpdater
- Defined in:
- lib/dependabot/nuget/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:, updated_value:, callsite_file:) ⇒ Object
Constructor Details
#initialize(dependency_files:) ⇒ PropertyValueUpdater
Returns a new instance of PropertyValueUpdater.
13 14 15 |
# File 'lib/dependabot/nuget/file_updater/property_value_updater.rb', line 13 def initialize(dependency_files:) @dependency_files = dependency_files end |
Instance Method Details
#update_files_for_property_change(property_name:, updated_value:, callsite_file:) ⇒ 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 |
# File 'lib/dependabot/nuget/file_updater/property_value_updater.rb', line 17 def update_files_for_property_change(property_name:, updated_value:, callsite_file:) declaration_details = property_value_finder. property_details( property_name: property_name, callsite_file: callsite_file ) declaration_file = dependency_files.find do |f| declaration_details.fetch(:file) == f.name end node = declaration_details.fetch(:node) updated_content = declaration_file.content.sub( %r{(<#{Regexp.quote(node.name)}(?:\s[^>]*)?>) \s*#{Regexp.quote(node.content)}\s* </#{Regexp.quote(node.name)}>}xm, '\1' + "#{updated_value}</#{node.name}>" ) files = dependency_files.dup files[files.index(declaration_file)] = update_file(file: declaration_file, content: updated_content) files end |