Class: Rbcli::Autoupdate::GemUpdater

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/rbcli/features/autoupdate/gem_updater.rb

Instance Method Summary collapse

Methods included from Common

#show_message, #update_available?

Constructor Details

#initialize(gemname, force_update, message) ⇒ GemUpdater

Returns a new instance of GemUpdater.



29
30
31
32
33
34
# File 'lib/rbcli/features/autoupdate/gem_updater.rb', line 29

def initialize gemname, force_update, message
	@gemname = gemname
	@uri = URI.parse "https://rubygems.org/api/v1/versions/#{gemname}/latest.json"
	@force_update = force_update
	@message = message
end

Instance Method Details

#get_latest_versionObject



36
37
38
39
40
41
42
43
# File 'lib/rbcli/features/autoupdate/gem_updater.rb', line 36

def get_latest_version
	begin
		response = Net::HTTP.get(@uri)
		JSON.parse(response)['version']
	rescue SocketError => e
		# Capture connection errors
	end
end

#update_messageObject



45
46
47
# File 'lib/rbcli/features/autoupdate/gem_updater.rb', line 45

def update_message
	"Please run `gem update #{@gemname}` to upgrade to the latest version. You can see it at: https://rubygems.org/gems/#{@gemname}/versions/#{@latest_version}"
end