Class: Dependabot::UpdateCheckers::Ruby::Bundler::RubyRequirementSetter

Inherits:
Object
  • Object
show all
Defined in:
lib/dependabot/update_checkers/ruby/bundler/ruby_requirement_setter.rb

Defined Under Namespace

Classes: GemfileRewriter

Constant Summary collapse

RUBY_VERSIONS =
%w(1.8.7 1.9.3 2.0.0 2.1.10 2.2.10 2.3.7 2.4.4 2.5.1).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gemspec:) ⇒ RubyRequirementSetter

Returns a new instance of RubyRequirementSetter.



16
17
18
# File 'lib/dependabot/update_checkers/ruby/bundler/ruby_requirement_setter.rb', line 16

def initialize(gemspec:)
  @gemspec = gemspec
end

Instance Attribute Details

#gemspecObject (readonly)

Returns the value of attribute gemspec.



14
15
16
# File 'lib/dependabot/update_checkers/ruby/bundler/ruby_requirement_setter.rb', line 14

def gemspec
  @gemspec
end

Instance Method Details

#rewrite(content) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/dependabot/update_checkers/ruby/bundler/ruby_requirement_setter.rb', line 20

def rewrite(content)
  return content unless gemspec_declares_ruby_requirement?

  buffer = Parser::Source::Buffer.new("(gemfile_content)")
  buffer.source = content
  ast = Parser::CurrentRuby.new.parse(buffer)

  if declares_ruby_version?(ast)
    GemfileRewriter.new(
      ruby_version: ruby_version
    ).rewrite(buffer, ast)
  else
    "ruby '#{ruby_version}'\n" + content
  end
end