Class: Dependabot::Bundler::FileUpdater::GitSourceRemover::Rewriter

Inherits:
Parser::TreeRewriter
  • Object
show all
Defined in:
lib/dependabot/bundler/file_updater/git_source_remover.rb

Constant Summary collapse

GOOD_KEYS =

TODO: Hack until Bundler 1.16.0 is available on Heroku

%i(
  group groups path glob name require platform platforms type
  source install_if
).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dependency:) ⇒ Rewriter

Returns a new instance of Rewriter.



33
34
35
# File 'lib/dependabot/bundler/file_updater/git_source_remover.rb', line 33

def initialize(dependency:)
  @dependency = dependency
end

Instance Attribute Details

#dependencyObject (readonly)

Returns the value of attribute dependency.



31
32
33
# File 'lib/dependabot/bundler/file_updater/git_source_remover.rb', line 31

def dependency
  @dependency
end

Instance Method Details

#on_send(node) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/dependabot/bundler/file_updater/git_source_remover.rb', line 37

def on_send(node)
  return unless declares_targeted_gem?(node)
  return unless node.children.last.type == :hash

  kwargs_node = node.children.last
  keys = kwargs_node.children.map do |hash_pair|
    key_from_hash_pair(hash_pair)
  end

  if keys.none? { |key| GOOD_KEYS.include?(key) }
    remove_all_kwargs(node)
  else
    remove_git_related_kwargs(kwargs_node)
  end
end