Class: Biosphere::CLI::UpdateManager

Inherits:
Object
  • Object
show all
Defined in:
lib/biosphere/cli/updatemanager.rb

Class Method Summary collapse

Class Method Details

.check_for_update(current_version = ::Biosphere::Version) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/biosphere/cli/updatemanager.rb', line 12

def self.check_for_update(current_version = ::Biosphere::Version)
    begin
        response = RestClient::Request.execute(method: :get, url: 'https://rubygems.org/api/v1/versions/biosphere/latest.json', timeout: 1)

        if response.code != 200
            return nil
        end

        data = JSON.parse(response.body)

        info = {
            latest: data["version"],
            current: current_version,
        }

        info[:up_to_date] = Gem::Version.new(info[:current]) == Gem::Version.new(info[:latest])

        return info
    rescue JSON::ParserError
        return nil
    rescue RestClient::Exceptions::OpenTimeout
        return nil
    rescue RestClient::Exceptions::ReadTimeout
        return nil
    end
end