Method: GemCheckUpdates::Gemfile#update

Defined in:
lib/gem_check_updates/gemfile.rb

#updateObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/gem_check_updates/gemfile.rb', line 68

def update
  gemfile_lines = []

  File.open(@option.file) do |current|
    current.each_line do |line|
      gemfile_lines << line
    end
  end

  File.open(@option.file, 'w') do |updated|
    gemfile_lines.each do |line|
      matcher = line.match(/gem ['"](.+?)['"]\s*,\s*['"][>=|~>]*\s+(.+?)['"]/)

      if matcher
        _, name, old_version = *matcher
        target = @gems.find { |gem| gem.name == name }

        line.gsub!(old_version, target.latest_version.to_s) unless target.nil?
      end

      updated.puts(line)
    end
  end
end