Class: Dependabot::FileUpdaters::Ruby::Bundler::GemspecDependencyNameFinder

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



13
14
15
# File 'lib/dependabot/file_updaters/ruby/bundler/gemspec_dependency_name_finder.rb', line 13

def initialize(gemspec_content:)
  @gemspec_content = gemspec_content
end

Instance Attribute Details

#gemspec_contentObject (readonly)

Returns the value of attribute gemspec_content.



11
12
13
# File 'lib/dependabot/file_updaters/ruby/bundler/gemspec_dependency_name_finder.rb', line 11

def gemspec_content
  @gemspec_content
end

Instance Method Details

#dependency_nameObject

rubocop:disable Security/Eval



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/dependabot/file_updaters/ruby/bundler/gemspec_dependency_name_finder.rb', line 18

def dependency_name
  ast = Parser::CurrentRuby.parse(gemspec_content)
  dependency_name_node = find_dependency_name_node(ast)
  return unless dependency_name_node

  begin
    eval(dependency_name_node.children[2].loc.expression.source)
  rescue StandardError
    nil # If we can't evaluate the expression just return nil
  end
end