Class: Dependabot::Bundler::FileUpdater::RequirementReplacer
- Inherits:
-
Object
- Object
- Dependabot::Bundler::FileUpdater::RequirementReplacer
- Defined in:
- lib/dependabot/bundler/file_updater/requirement_replacer.rb
Defined Under Namespace
Classes: Rewriter
Instance Attribute Summary collapse
-
#dependency ⇒ Object
readonly
Returns the value of attribute dependency.
-
#file_type ⇒ Object
readonly
Returns the value of attribute file_type.
-
#previous_requirement ⇒ Object
readonly
Returns the value of attribute previous_requirement.
-
#updated_requirement ⇒ Object
readonly
Returns the value of attribute updated_requirement.
Instance Method Summary collapse
-
#initialize(dependency:, file_type:, updated_requirement:, previous_requirement: nil, insert_if_bare: false) ⇒ RequirementReplacer
constructor
A new instance of RequirementReplacer.
- #rewrite(content) ⇒ Object
Constructor Details
#initialize(dependency:, file_type:, updated_requirement:, previous_requirement: nil, insert_if_bare: false) ⇒ RequirementReplacer
Returns a new instance of RequirementReplacer.
16 17 18 19 20 21 22 23 |
# File 'lib/dependabot/bundler/file_updater/requirement_replacer.rb', line 16 def initialize(dependency:, file_type:, updated_requirement:, previous_requirement: nil, insert_if_bare: false) @dependency = dependency @file_type = file_type @updated_requirement = updated_requirement @previous_requirement = previous_requirement @insert_if_bare = end |
Instance Attribute Details
#dependency ⇒ Object (readonly)
Returns the value of attribute dependency.
11 12 13 |
# File 'lib/dependabot/bundler/file_updater/requirement_replacer.rb', line 11 def dependency @dependency end |
#file_type ⇒ Object (readonly)
Returns the value of attribute file_type.
12 13 14 |
# File 'lib/dependabot/bundler/file_updater/requirement_replacer.rb', line 12 def file_type @file_type end |
#previous_requirement ⇒ Object (readonly)
Returns the value of attribute previous_requirement.
14 15 16 |
# File 'lib/dependabot/bundler/file_updater/requirement_replacer.rb', line 14 def previous_requirement @previous_requirement end |
#updated_requirement ⇒ Object (readonly)
Returns the value of attribute updated_requirement.
13 14 15 |
# File 'lib/dependabot/bundler/file_updater/requirement_replacer.rb', line 13 def updated_requirement @updated_requirement end |
Instance Method Details
#rewrite(content) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/dependabot/bundler/file_updater/requirement_replacer.rb', line 25 def rewrite(content) buffer = Parser::Source::Buffer.new("(gemfile_content)") buffer.source = content ast = Parser::CurrentRuby.new.parse(buffer) updated_content = Rewriter.new( dependency: dependency, file_type: file_type, updated_requirement: updated_requirement, insert_if_bare: ).rewrite(buffer, ast) update_comment_spacing_if_required(content, updated_content) end |