Class: Solaris::Patch
- Inherits:
-
Object
- Object
- Solaris::Patch
- Includes:
- Comparable
- Defined in:
- lib/solaris/patch.rb,
lib/solaris/exception.rb
Overview
Class to represent a patch number.
Defined Under Namespace
Classes: BadSuccessor, Exception, InvalidSuccessor, MultipleSuccessors, NotFound, NotObsolete
Constant Summary collapse
- URL =
Hash of URL patterns for downloads of type :patch or :readme. The string format parameter (%s) is the full patch number.
{ :patch => 'https://getupdates.oracle.com/all_unsigned/%s.zip', :readme => 'https://getupdates.oracle.com/readme/README.%s' }
Instance Attribute Summary collapse
-
#major ⇒ Object
The major number of the patch (integer), the part before the dash.
-
#minor ⇒ Object
The minor number of the patch (integer), the part after the dash.
Class Method Summary collapse
-
.download_patch!(patch, opts = {}) ⇒ Object
Download the given patch (this may be a Patch object or a string like ‘123456-78’).
-
.download_readme!(patch, opts = {}) ⇒ Object
Download the given readme (this may be a Patch object or a string like ‘123456-78’).
-
.pad_minor(minor) ⇒ Object
Left pad a minor version number with zeros as required.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Compare patch versions.
-
#download_patch!(opts = {}) ⇒ Object
Download this patch.
-
#download_readme!(opts = {}) ⇒ Object
Download this README.
-
#initialize(major = nil, minor = nil) ⇒ Patch
constructor
Create a patch.
-
#to_s ⇒ Object
Return a string representation of this patch.
Constructor Details
#initialize(major = nil, minor = nil) ⇒ Patch
Create a patch. May take zero, one or two parameters.
In the one parameter form, this is a string of the patch number eg ‘123456-78’. (If you specify integer 123456-78 then the resulting object will have major number 123378 and no minor number; this is probably not what you want).
In the two parameter form, the first parameter is the major patch number (123456) and the second is the minor number (78). Although it is possible to provide strings or integers here strings should be prefered since a leading zero on an integer in Ruby indicates an octal representation (in the tradition of C). This can cause problems with a revision number of 09, since this is not a valid octal representation.
TLDR: Patch.new(‘123456-78’)
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/solaris/patch.rb', line 46 def initialize(major=nil, minor=nil) if major patch_no = major.to_s + ( minor ? "-#{minor}" : '' ) if patch_no =~ /^(\d+)(-(\d+))?$/ @major = $1.to_i @minor = $3.to_i if $3 else raise ArgumentError, "Invalid patch number string #{patch_no.inspect}" end end end |
Instance Attribute Details
#major ⇒ Object
The major number of the patch (integer), the part before the dash.
22 23 24 |
# File 'lib/solaris/patch.rb', line 22 def major @major end |
#minor ⇒ Object
The minor number of the patch (integer), the part after the dash. Since this is an integer, values less than 10 will not be left padded with zero (see Patch::pad_minor). May be nil if not specified in the constructor.
28 29 30 |
# File 'lib/solaris/patch.rb', line 28 def minor @minor end |
Class Method Details
.download_patch!(patch, opts = {}) ⇒ Object
Download the given patch (this may be a Patch object or a string like ‘123456-78’). For the options hash see Patch#download!.
81 82 83 84 |
# File 'lib/solaris/patch.rb', line 81 def Patch.download_patch!(patch, opts={}) patch_to_dl = Patch.new( patch.to_s ) patch_to_dl.download_patch!( opts ) end |
.download_readme!(patch, opts = {}) ⇒ Object
Download the given readme (this may be a Patch object or a string like ‘123456-78’). For the options hash see Patch#download!.
88 89 90 91 |
# File 'lib/solaris/patch.rb', line 88 def Patch.download_readme!(patch, opts={}) patch_to_dl = Patch.new( patch.to_s ) patch_to_dl.download_readme!( opts ) end |
.pad_minor(minor) ⇒ Object
Left pad a minor version number with zeros as required.
94 95 96 |
# File 'lib/solaris/patch.rb', line 94 def Patch.pad_minor(minor) "#{minor.to_s.rjust( 2, '0' )}" end |
Instance Method Details
#<=>(other) ⇒ Object
Compare patch versions. (Performs a string compare on the full patch numbers).
75 76 77 |
# File 'lib/solaris/patch.rb', line 75 def <=>(other) self.to_s <=> other.to_s end |
#download_patch!(opts = {}) ⇒ Object
Download this patch. For the options hash see private method Patch#download!
59 60 61 |
# File 'lib/solaris/patch.rb', line 59 def download_patch!(opts={}) download!( :patch, opts ) end |
#download_readme!(opts = {}) ⇒ Object
Download this README. For the options hash see private method Patch#download!
64 65 66 |
# File 'lib/solaris/patch.rb', line 64 def download_readme!(opts={}) download!( :readme, opts ) end |
#to_s ⇒ Object
Return a string representation of this patch. If the minor number has not been set then just return the major number.
70 71 72 |
# File 'lib/solaris/patch.rb', line 70 def to_s minor ? "#{@major}-#{Patch.pad_minor( @minor )}" : "#{@major}" end |