Class: Dependabot::Bundler::FileUpdater::GemspecDependencyNameFinder

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dependabot/bundler/file_updater/gemspec_dependency_name_finder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gemspec_content:) ⇒ GemspecDependencyNameFinder

Returns a new instance of GemspecDependencyNameFinder.



17
18
19
# File 'lib/dependabot/bundler/file_updater/gemspec_dependency_name_finder.rb', line 17

def initialize(gemspec_content:)
  @gemspec_content = gemspec_content
end

Instance Attribute Details

#gemspec_contentObject (readonly)

Returns the value of attribute gemspec_content.



14
15
16
# File 'lib/dependabot/bundler/file_updater/gemspec_dependency_name_finder.rb', line 14

def gemspec_content
  @gemspec_content
end

Instance Method Details

#dependency_nameObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/dependabot/bundler/file_updater/gemspec_dependency_name_finder.rb', line 23

def dependency_name
  result = Prism.parse(gemspec_content)
  dependency_name_node = find_dependency_name_node(result.value)
  return unless dependency_name_node.is_a?(Prism::CallNode)

  arg_node = dependency_name_node.arguments&.arguments&.first
  return if arg_node.nil?

  begin
    eval(arg_node.slice)
  rescue StandardError
    nil # If we can't evaluate the expression just return nil
  end
end