class Solaris::Patch

Class to represent a patch number.

Constants

URL

Hash of URL patterns for downloads of type :patch or :readme. The string format parameter (%s) is the full patch number.

Attributes

major[RW]

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

minor[RW]

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 ::pad_minor). May be nil if not specified in the constructor.

Public Class Methods

download_patch!(patch, opts={}) click to toggle source

Download the given patch (this may be a Patch object or a string like ‘123456-78’). For the options hash see #download!.

# 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={}) click to toggle source

Download the given readme (this may be a Patch object or a string like ‘123456-78’). For the options hash see #download!.

# 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
new(major=nil, minor=nil) click to toggle source

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: ::new(‘123456-78’)

# 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 =~ %r^(\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
pad_minor(minor) click to toggle source

Left pad a minor version number with zeros as required.

# File lib/solaris/patch.rb, line 94
def Patch.pad_minor(minor)
  "#{minor.to_s.rjust( 2, '0' )}"
end

Public Instance Methods

<=>(other) click to toggle source

Compare patch versions. (Performs a string compare on the full patch numbers).

# File lib/solaris/patch.rb, line 75
def <=>(other)
  self.to_s <=> other.to_s
end
download_patch!(opts={}) click to toggle source

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

# File lib/solaris/patch.rb, line 59
def download_patch!(opts={})
  download!( :patch, opts )
end
download_readme!(opts={}) click to toggle source

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

# File lib/solaris/patch.rb, line 64
def download_readme!(opts={})
  download!( :readme, opts )
end
to_s() click to toggle source

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

# File lib/solaris/patch.rb, line 70
def to_s
  minor ? "#{@major}-#{Patch.pad_minor( @minor )}" : "#{@major}"
end

Private Instance Methods

download!(type, opts={}) click to toggle source

Download this patch or readme from Oracle. For the options hash argument see Solaris::Util.download!

# File lib/solaris/patch.rb, line 102
def download!(type, opts={})
  raise ArgumentError, "Patch #{self.inspect} requires a major number to download" unless @major
  raise ArgumentError, "Patch #{self.inspect} requires a minor number to download" unless @minor
  raise ArgumentError, "Unknown type #{type.inspect}" unless URL[ type ]
  url = URL[ type ] % self.to_s
  opts = {
    :agent => 'Wget/1.10.2', # default user agent, required by Oracle
  }.merge( opts )
  Solaris::Util.download!( url, opts )
end