class GemUpdater::Updater

Updater's main responsability is to fill changes happened before and after update of `Gemfile`, and then format them.

Attributes

gemfile[RW]

Public Class Methods

new() click to toggle source
# File lib/gem_updater.rb, line 18
def initialize
  @gemfile = GemUpdater::GemFile.new
end

Public Instance Methods

format_diff() click to toggle source

Format the diff to get human readable information on the gems that were updated.

# File lib/gem_updater.rb, line 42
def format_diff
  erb = if RUBY_VERSION.to_f < 3.0
          ERB.new(template, nil, '<>')
        else
          ERB.new(template, trim_mode: '<>')
        end

  gemfile.changes.map do |gem, details|
    erb.result(binding)
  end
end
output_diff() click to toggle source

Print formatted diff

# File lib/gem_updater.rb, line 36
def output_diff
  Bundler.ui.info format_diff.join
end
update!(gems) click to toggle source

Update process. This will:

1. update gemfile
2. find changelogs for updated gems

@param gems [Array] list of gems to update

# File lib/gem_updater.rb, line 28
def update!(gems)
  gemfile.update!(gems)
  gemfile.compute_changes

  fill_changelogs
end

Private Instance Methods

fill_changelogs() click to toggle source

For each gem, retrieve its changelog

# File lib/gem_updater.rb, line 57
def fill_changelogs
  [].tap do |threads|
    gemfile.changes.each do |gem_name, details|
      threads << Thread.new { retrieve_gem_changes(gem_name, details) }
    end
  end.each(&:join)
end
find_source(gem, source) click to toggle source

Find where is hosted the source of a gem

@param gem [String] the name of the gem @param source [Bundler::Source] gem's source @return [String] url where gem is hosted

# File lib/gem_updater.rb, line 70
def find_source(gem, source)
  case source
  when Bundler::Source::Rubygems
    GemUpdater::RubyGemsFetcher.new(gem, source).source_uri
  when Bundler::Source::Git
    source.uri.gsub(/^git/, 'http').chomp('.git')
  end
end
retrieve_gem_changes(gem_name, details) click to toggle source
# File lib/gem_updater.rb, line 79
def retrieve_gem_changes(gem_name, details)
  source_uri = find_source(gem_name, details[:source])
  return unless source_uri

  source_page = GemUpdater::SourcePageParser.new(
    url: source_uri, version: details[:versions][:new]
  )

  gemfile.changes[gem_name][:changelog] = source_page.changelog if source_page.changelog
end
template() click to toggle source

Get the template for gem's diff. It can use a custom template.

@return [ERB] the template

# File lib/gem_updater.rb, line 94
def template
  File.read("#{Dir.home}/.gem_updater_template.erb")
rescue Errno::ENOENT
  File.read(File.expand_path('../lib/gem_updater_template.erb', __dir__))
end