Class: Dependabot::Python::FileUpdater::RequirementReplacer
- Inherits:
-
Object
- Object
- Dependabot::Python::FileUpdater::RequirementReplacer
- Defined in:
- lib/dependabot/python/file_updater/requirement_replacer.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#dependency_name ⇒ Object
readonly
Returns the value of attribute dependency_name.
-
#new_requirement ⇒ Object
readonly
Returns the value of attribute new_requirement.
-
#old_requirement ⇒ Object
readonly
Returns the value of attribute old_requirement.
Instance Method Summary collapse
-
#initialize(content:, dependency_name:, old_requirement:, new_requirement:) ⇒ RequirementReplacer
constructor
A new instance of RequirementReplacer.
- #updated_content ⇒ Object
Constructor Details
#initialize(content:, dependency_name:, old_requirement:, new_requirement:) ⇒ RequirementReplacer
Returns a new instance of RequirementReplacer.
14 15 16 17 18 19 20 |
# File 'lib/dependabot/python/file_updater/requirement_replacer.rb', line 14 def initialize(content:, dependency_name:, old_requirement:, new_requirement:) @content = content @dependency_name = dependency_name @old_requirement = old_requirement @new_requirement = new_requirement end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
11 12 13 |
# File 'lib/dependabot/python/file_updater/requirement_replacer.rb', line 11 def content @content end |
#dependency_name ⇒ Object (readonly)
Returns the value of attribute dependency_name.
11 12 13 |
# File 'lib/dependabot/python/file_updater/requirement_replacer.rb', line 11 def dependency_name @dependency_name end |
#new_requirement ⇒ Object (readonly)
Returns the value of attribute new_requirement.
11 12 13 |
# File 'lib/dependabot/python/file_updater/requirement_replacer.rb', line 11 def new_requirement @new_requirement end |
#old_requirement ⇒ Object (readonly)
Returns the value of attribute old_requirement.
11 12 13 |
# File 'lib/dependabot/python/file_updater/requirement_replacer.rb', line 11 def old_requirement @old_requirement end |
Instance Method Details
#updated_content ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/dependabot/python/file_updater/requirement_replacer.rb', line 22 def updated_content updated_content = content.gsub(original_declaration_replacement_regex) do |mtch| # If the "declaration" is setting an option (e.g., no-binary) # ignore it, since it isn't actually a declaration next mtch if Regexp.last_match.pre_match.match?(/--.*\z/) updated_dependency_declaration_string( old_requirement, new_requirement ) end raise "Expected content to change!" if content == updated_content updated_content end |