-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
NetSHH Robot
committed
Dec 25, 2024
1 parent
9477908
commit 128b266
Showing
2 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
module Net | ||
class SCP | ||
# A class for describing the current version of a library. The version | ||
# consists of three parts: the +major+ number, the +minor+ number, and the | ||
# +tiny+ (or +patch+) number. | ||
# | ||
# Two Version instances may be compared, so that you can test that a version | ||
# of a library is what you require: | ||
# | ||
# require 'net/scp/version' | ||
# | ||
# if Net::SCP::Version::CURRENT < Net::SCP::Version[2,1,0] | ||
# abort "your software is too old!" | ||
# end | ||
class Version | ||
include Comparable | ||
|
||
# A convenience method for instantiating a new Version instance with the | ||
# given +major+, +minor+, and +tiny+ components. | ||
def self.[](major, minor, tiny, pre = nil) | ||
new(major, minor, tiny, pre) | ||
end | ||
|
||
attr_reader :major, :minor, :tiny | ||
|
||
# Create a new Version object with the given components. | ||
def initialize(major, minor, tiny, pre = nil) | ||
@major, @minor, @tiny, @pre = major, minor, tiny, pre | ||
end | ||
|
||
# Compare this version to the given +version+ object. | ||
def <=>(version) | ||
to_i <=> version.to_i | ||
end | ||
|
||
# Converts this version object to a string, where each of the three | ||
# version components are joined by the '.' character. E.g., 2.0.0. | ||
def to_s | ||
@to_s ||= [@major, @minor, @tiny, @pre].compact.join(".") | ||
end | ||
|
||
# Converts this version to a canonical integer that may be compared | ||
# against other version objects. | ||
def to_i | ||
@to_i ||= @major * 1_000_000 + @minor * 1_000 + @tiny | ||
end | ||
|
||
# The major component of this version of the Net::SSH library | ||
MAJOR = 4 | ||
|
||
# The minor component of this version of the Net::SSH library | ||
MINOR = 0 | ||
|
||
# The tiny component of this version of the Net::SSH library | ||
TINY = 1 | ||
|
||
# The prerelease component of this version of the Net::SSH library | ||
# nil allowed | ||
PRE = "rc1" | ||
|
||
# The current version of the Net::SSH library as a Version instance | ||
CURRENT = new(*[MAJOR, MINOR, TINY, PRE].compact) | ||
|
||
# The current version of the Net::SSH library as a String | ||
STRING = CURRENT.to_s | ||
end | ||
end | ||
end |