Class: Dependabot::Bundler::FileUpdater::RequirementReplacer::Rewriter
- Inherits:
-
Parser::TreeRewriter
- Object
- Parser::TreeRewriter
- Dependabot::Bundler::FileUpdater::RequirementReplacer::Rewriter
- Defined in:
- lib/dependabot/bundler/file_updater/requirement_replacer.rb
Constant Summary collapse
- SKIPPED_TYPES =
TODO: Ideally we wouldn’t have to ignore all of these, but implementing each one will be tricky.
%i(send lvar dstr begin if case splat const or).freeze
Instance Method Summary collapse
-
#initialize(dependency:, file_type:, updated_requirement:, insert_if_bare:) ⇒ Rewriter
constructor
A new instance of Rewriter.
- #on_send(node) ⇒ Object
Constructor Details
#initialize(dependency:, file_type:, updated_requirement:, insert_if_bare:) ⇒ Rewriter
Returns a new instance of Rewriter.
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/dependabot/bundler/file_updater/requirement_replacer.rb', line 81 def initialize(dependency:, file_type:, updated_requirement:, insert_if_bare:) @dependency = dependency @file_type = file_type @updated_requirement = updated_requirement @insert_if_bare = return if %i(gemfile gemspec).include?(file_type) raise "File type must be :gemfile or :gemspec. Got #{file_type}." end |
Instance Method Details
#on_send(node) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/dependabot/bundler/file_updater/requirement_replacer.rb', line 93 def on_send(node) return unless declares_targeted_gem?(node) req_nodes = node.children[3..-1] req_nodes = req_nodes.reject { |child| child.type == :hash } return if req_nodes.none? && ! return if req_nodes.any? { |n| SKIPPED_TYPES.include?(n.type) } quote_characters = extract_quote_characters_from(req_nodes) space_after_specifier = space_after_specifier?(req_nodes) use_equality_operator = use_equality_operator?(req_nodes) new_req = new_requirement_string( quote_characters: quote_characters, space_after_specifier: space_after_specifier, use_equality_operator: use_equality_operator ) if req_nodes.any? replace(range_for(req_nodes), new_req) else insert_after(range_for(node.children[2..2]), ", #{new_req}") end end |