Class: BetterCap::UpdateChecker
- Inherits:
-
Object
- Object
- BetterCap::UpdateChecker
- Defined in:
- lib/bettercap/update_checker.rb
Overview
bettercap and check if a new one is available.
Class Method Summary collapse
-
.check ⇒ Object
Check if a new version is available, printing the results in human readable form.
-
.get_latest_version ⇒ Object
Fetch the latest program version from rubygems.org API.
-
.vton(v) ⇒ Object
Convert a version string
v
to a number to be used for comparation.
Class Method Details
.check ⇒ Object
Check if a new version is available, printing the results in human readable form.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/bettercap/update_checker.rb', line 20 def self.check ver = self.get_latest_version if self.vton( BetterCap::VERSION ) < self.vton( ver ) Logger.warn "New version '#{ver}' available!" else Logger.info 'You are running the latest version.' end rescue Exception => e Logger.error("Error '#{e.class}' while checking for updates: #{e.}") end |
.get_latest_version ⇒ Object
Fetch the latest program version from rubygems.org API.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/bettercap/update_checker.rb', line 41 def self.get_latest_version Logger.info 'Checking for updates ...' api = URI('https://rubygems.org/api/v1/versions/bettercap/latest.json') response = Net::HTTP.get_response(api) case response when Net::HTTPSuccess json = JSON.parse(response.body) else raise response. end return json['version'] end |
.vton(v) ⇒ Object
Convert a version string v
to a number to be used for comparation.
32 33 34 35 36 37 38 |
# File 'lib/bettercap/update_checker.rb', line 32 def self.vton v vi = 0.0 v.split('.').reverse.each_with_index do |e,i| vi += ( e.to_i * 10**i ) - ( e =~ /[\d+]b/ ? 0.5 : 0 ) end vi end |