Sha256: 91447a9ecafc5c6c437d1a4b06b75f9dc480a82ee118bbbab2d17976df48ac6a

Contents?: true

Size: 1.88 KB

Versions: 20

Compression:

Stored size: 1.88 KB

Contents

# frozen_string_literal: true

require "nokogiri"

require "dependabot/dependency_file"
require "dependabot/file_updaters/dotnet/nuget"
require "dependabot/file_parsers/dotnet/nuget/property_value_finder"

module Dependabot
  module FileUpdaters
    module Dotnet
      class Nuget
        class PropertyValueUpdater
          def initialize(dependency_files:)
            @dependency_files = dependency_files
          end

          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*#{Regexp.quote(node.content)}\s*
                 </#{Regexp.quote(node.name)}>}xm,
              "<#{node.name}>#{updated_value}</#{node.name}>"
            )

            files = dependency_files.dup
            files[files.index(declaration_file)] =
              update_file(file: declaration_file, content: updated_content)
            files
          end

          private

          attr_reader :dependency_files

          def property_value_finder
            @property_value_finder ||=
              FileParsers::Dotnet::Nuget::PropertyValueFinder.
              new(dependency_files: dependency_files)
          end

          def update_file(file:, content:)
            updated_file = file.dup
            updated_file.content = content
            updated_file
          end
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
dependabot-core-0.79.4 lib/dependabot/file_updaters/dotnet/nuget/property_value_updater.rb
dependabot-core-0.79.3 lib/dependabot/file_updaters/dotnet/nuget/property_value_updater.rb
dependabot-core-0.79.2 lib/dependabot/file_updaters/dotnet/nuget/property_value_updater.rb
dependabot-core-0.79.1 lib/dependabot/file_updaters/dotnet/nuget/property_value_updater.rb
dependabot-core-0.79.0 lib/dependabot/file_updaters/dotnet/nuget/property_value_updater.rb
dependabot-core-0.78.0 lib/dependabot/file_updaters/dotnet/nuget/property_value_updater.rb
dependabot-core-0.77.2 lib/dependabot/file_updaters/dotnet/nuget/property_value_updater.rb
dependabot-core-0.77.1 lib/dependabot/file_updaters/dotnet/nuget/property_value_updater.rb
dependabot-core-0.77.0 lib/dependabot/file_updaters/dotnet/nuget/property_value_updater.rb
dependabot-core-0.76.11 lib/dependabot/file_updaters/dotnet/nuget/property_value_updater.rb
dependabot-core-0.76.10 lib/dependabot/file_updaters/dotnet/nuget/property_value_updater.rb
dependabot-core-0.76.9 lib/dependabot/file_updaters/dotnet/nuget/property_value_updater.rb
dependabot-core-0.76.8 lib/dependabot/file_updaters/dotnet/nuget/property_value_updater.rb
dependabot-core-0.76.7 lib/dependabot/file_updaters/dotnet/nuget/property_value_updater.rb
dependabot-core-0.76.6 lib/dependabot/file_updaters/dotnet/nuget/property_value_updater.rb
dependabot-core-0.76.5 lib/dependabot/file_updaters/dotnet/nuget/property_value_updater.rb
dependabot-core-0.76.4 lib/dependabot/file_updaters/dotnet/nuget/property_value_updater.rb
dependabot-core-0.76.3 lib/dependabot/file_updaters/dotnet/nuget/property_value_updater.rb
dependabot-core-0.76.2 lib/dependabot/file_updaters/dotnet/nuget/property_value_updater.rb
dependabot-core-0.76.1 lib/dependabot/file_updaters/dotnet/nuget/property_value_updater.rb