class SSHScan::Update
Handle {SSHScan} updates.
Public Class Methods
new()
click to toggle source
# File lib/ssh_scan/update.rb, line 9 def initialize @errors = [] end
Public Instance Methods
errors()
click to toggle source
# File lib/ssh_scan/update.rb, line 57 def errors @errors.uniq end
gem_exists?(version = SSHScan::VERSION)
click to toggle source
Returns true if the given gem version exists. @param version [String] version string @return [Boolean] true if given gem exists, else false
# File lib/ssh_scan/update.rb, line 40 def gem_exists?(version = SSHScan::VERSION) uri = URI("https://rubygems.org/gems/ssh_scan/versions/#{version}") begin res = Net::HTTP.get_response(uri) rescue SocketError => e @errors << e.message return false end if res.code != "200" return false else return true end end
newer_gem_available?(version = SSHScan::VERSION)
click to toggle source
Tries to check if the next patch, minor or major version is available or not. If so, returns true. @param version [String] version string @return [Boolean] true if next major/minor version available,
else false
# File lib/ssh_scan/update.rb, line 66 def newer_gem_available?(version = SSHScan::VERSION) if gem_exists?(next_patch_version(version)) return true end if gem_exists?(next_minor_version(version)) return true end if gem_exists?(next_major_version(version)) return true end return false end
next_major_version(version = SSHScan::VERSION)
click to toggle source
# File lib/ssh_scan/update.rb, line 29 def next_major_version(version = SSHScan::VERSION) major = version.split(".")[0] major_num = major.to_i major_num += 1 return [major_num.to_s, "0", "0"].join(".") end
next_minor_version(version = SSHScan::VERSION)
click to toggle source
# File lib/ssh_scan/update.rb, line 21 def next_minor_version(version = SSHScan::VERSION) major, minor = version.split(".")[0, 2] minor_num = minor.to_i minor_num += 1 return [major, minor_num.to_s, "0"].join(".") end
next_patch_version(version = SSHScan::VERSION)
click to toggle source
# File lib/ssh_scan/update.rb, line 13 def next_patch_version(version = SSHScan::VERSION) major, minor, patch = version.split(".") patch_num = patch.to_i patch_num += 1 return [major, minor, patch_num.to_s].join(".") end