Class: Dependabot::Bundler::FileUpdater::GemspecSanitizer
- Inherits:
-
Object
- Object
- Dependabot::Bundler::FileUpdater::GemspecSanitizer
- 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
-
#replacement_version ⇒ Object
readonly
Returns the value of attribute replacement_version.
Instance Method Summary collapse
-
#initialize(replacement_version:) ⇒ GemspecSanitizer
constructor
A new instance of GemspecSanitizer.
- #rewrite(content) ⇒ Object
Constructor Details
#initialize(replacement_version:) ⇒ GemspecSanitizer
Returns a new instance of GemspecSanitizer.
28 29 30 |
# File 'lib/dependabot/bundler/file_updater/gemspec_sanitizer.rb', line 28 def initialize(replacement_version:) @replacement_version = replacement_version end |
Instance Attribute Details
#replacement_version ⇒ Object (readonly)
Returns the value of attribute replacement_version.
26 27 28 |
# File 'lib/dependabot/bundler/file_updater/gemspec_sanitizer.rb', line 26 def replacement_version @replacement_version end |
Instance Method Details
#rewrite(content) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/dependabot/bundler/file_updater/gemspec_sanitizer.rb', line 32 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 |