Class: Dependabot::Bundler::FileUpdater::GemspecSanitizer

Inherits:
Object
  • Object
show all
Defined in:
lib/dependabot/bundler/file_updater/gemspec_sanitizer.rb

Defined Under Namespace

Classes: Rewriter

Constant Summary collapse

UNNECESSARY_ASSIGNMENTS =
%i(
  bindir=
  cert_chain=
  email=
  executables=
  extra_rdoc_files=
  date=
  homepage=
  license=
  licenses=
  metadata=
  post_install_message=
  rdoc_options=
).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(replacement_version:) ⇒ GemspecSanitizer

Returns a new instance of GemspecSanitizer.


27
28
29
# File 'lib/dependabot/bundler/file_updater/gemspec_sanitizer.rb', line 27

def initialize(replacement_version:)
  @replacement_version = replacement_version
end

Instance Attribute Details

#replacement_versionObject (readonly)

Returns the value of attribute replacement_version


25
26
27
# File 'lib/dependabot/bundler/file_updater/gemspec_sanitizer.rb', line 25

def replacement_version
  @replacement_version
end

Instance Method Details

#rewrite(content) ⇒ Object


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/dependabot/bundler/file_updater/gemspec_sanitizer.rb', line 31

def rewrite(content)
  buffer = Parser::Source::Buffer.new("(gemspec_content)")
  buffer.source = content
  ast = Parser::CurrentRuby.new.parse(buffer)

  updated_content =
    Rewriter.
    new(replacement_version: replacement_version).
    rewrite(buffer, ast)

  # Remove any constants from strings
  updated_content.gsub(
    /#\{[A-Z][^.}]*::[A-Z][^.}]*\}/,
    '#{"' + replacement_version.to_s + '"}'
  )
end