Class: Rbcli::Autoupdate::GemUpdater

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/rbcli/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.



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

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_version ⇒ Object



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

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

#update_message ⇒ Object



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

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