class P4ApiVersion

This captures the version information of the P4API C++ library we're building against. This is mostly parsed into this structure and then spit out into a header file we compile into the Ruby API.

Attributes

major[R]
minor[R]
patchlevel[RW]
suppdate[RW]
type[R]

Public Class Methods

load(dir) click to toggle source
# File ext/P4/extconf.rb, line 233
def P4ApiVersion.load(dir)
  #
  # 2007.2 and later APIs put the Version file in the 'sample'
  # subdirectory. Look there if we can't find it in the API root
  #
  ver_file = dir + "/Version"
  unless File.exists?(ver_file)
    ver_file = dir + "/sample/Version"
    return nil unless File.exists?(ver_file)
  end

  re = Regexp.new('^RELEASE = (\d+)\s+(\d+)\s+(\w*\S*)\s*;')
  rp = Regexp.new('^PATCHLEVEL = (.*)\s*;')
  rs = Regexp.new('^SUPPDATE = (.*)\s*;')

  p4api_version = nil

  File.open(ver_file, "r") do
  |f|
    f.each_line do
    |line|
      if md = re.match(line)
        p4api_version = P4ApiVersion.new(md[1], md[2])
        p4api_version.set_type(md[3])
      elsif md = rp.match(line)
        p4api_version.patchlevel = md[1]
      elsif md = rs.match(line)
        p4api_version.suppdate = md[1]
      end
    end
  end
  puts("Found #{p4api_version} Perforce API in #{dir}")
  return p4api_version
end
new(major, minor = nil) click to toggle source
# File ext/P4/extconf.rb, line 268
def initialize(major, minor = nil)
  if (major.kind_of?(String) && !minor)
    if (major =~ /(\d+)\.(\d+)/)
      major = $1
      minor = $2
    else
      raise("Bad API version: #{major}")
    end
  end

  @major = major.to_i
  @minor = minor.to_i
  @type = nil

  @patchlevel = nil
  @suppdate = nil
end

Public Instance Methods

<=>(other) click to toggle source
# File ext/P4/extconf.rb, line 309
def <=>(other)
  hi = @major <=> other.major
  lo = @minor <=> other.minor

  return hi == 0 ? lo : hi
end
set_type(type) click to toggle source
# File ext/P4/extconf.rb, line 286
def set_type(type)
  if (type.kind_of?(String))
    @type = type
  end
end
to_i() click to toggle source
# File ext/P4/extconf.rb, line 305
def to_i
  major << 8 | minor
end
to_s() click to toggle source
# File ext/P4/extconf.rb, line 297
def to_s
  if (@type and not @type.empty?)
    "#{major}.#{minor}.#{@type.upcase}"
  else
    "#{major}.#{minor}"
  end
end