class GemUpdater::Updater
Updater’s main responsability is to fill changes happened before and after update of ‘Gemfile`, and then format them.
Constants
- RUBYGEMS_SOURCE_NAME
Attributes
gemfile[RW]
Public Class Methods
new()
click to toggle source
# File lib/gem_updater.rb, line 17 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 41 def format_diff erb = ERB.new(template.force_encoding('UTF-8'), trim_mode: '<>') 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 35 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 27 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 52 def fill_changelogs gemfile.changes.map do |gem_changes, details| Thread.new { retrieve_changelog(gem_changes, details) } end.each(&:join) end
retrieve_changelog(gem_name, details)
click to toggle source
Get the changelog URL.
# File lib/gem_updater.rb, line 59 def retrieve_changelog(gem_name, details) return unless details[:source].name == RUBYGEMS_SOURCE_NAME changelog_uri = RubyGemsFetcher.new(gem_name).changelog_uri return unless changelog_uri changelog = ChangelogParser .new(uri: changelog_uri, version: details.dig(:versions, :new)).changelog gemfile.changes[gem_name][:changelog] = changelog&.to_s 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 75 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