Class: Dependabot::Bundler::FileUpdater::RequirementReplacer::Rewriter
- Inherits:
-
Parser::TreeRewriter
- Object
- Parser::TreeRewriter
- Dependabot::Bundler::FileUpdater::RequirementReplacer::Rewriter
- Extended by:
- T::Sig
- 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.
T.let(i(send lvar dstr begin if case splat const or).freeze, T::Array[Symbol])
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.
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/dependabot/bundler/file_updater/requirement_replacer.rb', line 129 def initialize( dependency:, file_type:, updated_requirement:, insert_if_bare: ) @dependency = T.let(dependency, Dependabot::Dependency) @file_type = T.let(file_type, Symbol) @updated_requirement = T.let(updated_requirement, String) = T.let(, T::Boolean) 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
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/dependabot/bundler/file_updater/requirement_replacer.rb', line 146 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 |