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

Inherits:
Object
  • Object
show all
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.



12
13
14
# File 'lib/dependabot/bundler/file_updater/gemspec_dependency_name_finder.rb', line 12

def initialize(gemspec_content:)
  @gemspec_content = gemspec_content
end

Instance Attribute Details

#gemspec_contentObject (readonly)

Returns the value of attribute gemspec_content.



10
11
12
# File 'lib/dependabot/bundler/file_updater/gemspec_dependency_name_finder.rb', line 10

def gemspec_content
  @gemspec_content
end

Instance Method Details

#dependency_nameObject

rubocop:disable Security/Eval



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

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