Class: Solaris::Patch

Inherits:
Object
  • Object
show all
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, SuccessorLoop

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

Class Method Summary collapse

Instance Method Summary collapse

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’)



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/solaris/patch.rb', line 45

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

#majorObject

The major number of the patch (integer), the part before the dash.



21
22
23
# File 'lib/solaris/patch.rb', line 21

def major
  @major
end

#minorObject

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.



27
28
29
# File 'lib/solaris/patch.rb', line 27

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!.



80
81
82
83
# File 'lib/solaris/patch.rb', line 80

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!.



87
88
89
90
# File 'lib/solaris/patch.rb', line 87

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.



93
94
95
# File 'lib/solaris/patch.rb', line 93

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).



74
75
76
# File 'lib/solaris/patch.rb', line 74

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!



58
59
60
# File 'lib/solaris/patch.rb', line 58

def download_patch!(opts={})
  download!(:patch, opts)
end

#download_readme!(opts = {}) ⇒ Object

Download this README. For the options hash see private method Patch#download!



63
64
65
# File 'lib/solaris/patch.rb', line 63

def download_readme!(opts={})
  download!(:readme, opts)
end

#to_sObject

Return a string representation of this patch. If the minor number has not been set then just return the major number.



69
70
71
# File 'lib/solaris/patch.rb', line 69

def to_s
  minor ? "#{@major}-#{Patch.pad_minor(@minor)}" : "#{@major}"
end