Class: Dependabot::FileUpdaters::Ruby::Bundler::GitPinReplacer::Rewriter

Inherits:
Parser::TreeRewriter
  • Object
show all
Defined in:
lib/dependabot/file_updaters/ruby/bundler/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.



32
33
34
35
# File 'lib/dependabot/file_updaters/ruby/bundler/git_pin_replacer.rb', line 32

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

Instance Attribute Details

#dependencyObject (readonly)

Returns the value of attribute dependency.



30
31
32
# File 'lib/dependabot/file_updaters/ruby/bundler/git_pin_replacer.rb', line 30

def dependency
  @dependency
end

#new_pinObject (readonly)

Returns the value of attribute new_pin.



30
31
32
# File 'lib/dependabot/file_updaters/ruby/bundler/git_pin_replacer.rb', line 30

def new_pin
  @new_pin
end

Instance Method Details

#on_send(node) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/dependabot/file_updaters/ruby/bundler/git_pin_replacer.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
  kwargs_node.children.each do |hash_pair|
    next unless PIN_KEYS.include?(key_from_hash_pair(hash_pair))

    update_value(hash_pair)
  end
end