Class: Dependabot::Bundler::FileUpdater::GitPinReplacer::Rewriter

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

Constant Summary collapse

PIN_KEYS =
%i(ref tag).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dependency:, new_pin:) ⇒ Rewriter

Returns a new instance of Rewriter.



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

def initialize(dependency:, new_pin:)
  @dependency = dependency
  @new_pin = new_pin
end

Instance Attribute Details

#dependencyObject (readonly)

Returns the value of attribute dependency.



29
30
31
# File 'lib/dependabot/bundler/file_updater/git_pin_replacer.rb', line 29

def dependency
  @dependency
end

#new_pinObject (readonly)

Returns the value of attribute new_pin.



29
30
31
# File 'lib/dependabot/bundler/file_updater/git_pin_replacer.rb', line 29

def new_pin
  @new_pin
end

Instance Method Details

#on_send(node) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/dependabot/bundler/file_updater/git_pin_replacer.rb', line 36

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

  kwargs_node = node.children.last
  kwargs_node.children.each do |hash_pair|
    next unless PIN_KEYS.include?(key_from_hash_pair(hash_pair))

    update_value(hash_pair)
  end
end