Class: Beaker::Platform

Inherits:
String
  • Object
show all
Defined in:
lib/beaker/platform.rb

Overview

This class create a Platform object inheriting from String. It supports all String methods while adding several platform-specific use cases.

Constant Summary collapse

PLATFORMS =

Supported platforms

/^(osx|centos|fedora|debian|oracle|redhat|scientific|sles|ubuntu|windows|solaris|aix|el)\-.+\-.+$/
PLATFORM_VERSION_CODES =

Platform version numbers vs. codenames conversion hash

{ :debian => { "wheezy"  => "7",
               "squeeze" => "6",
             },
  :ubuntu => { "trusty"  => "1404",
               "saucy"   => "1310",
               "raring"  => "1304",
               "quantal" => "1210",
               "precise" => "1204",
             },
}

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Platform

Creates the Platform object. Checks to ensure that the platform String provided meets the platform formatting rules. Platforms name must be of the format /^OSFAMILY-VERSION-ARCH.*$/ where OSFAMILY is one of:

  • centos

  • fedora

  • debian

  • oracle

  • redhat

  • scientific

  • sles

  • ubuntu

  • windows

  • solaris

  • aix

  • el



34
35
36
37
38
39
# File 'lib/beaker/platform.rb', line 34

def initialize(name)
  if name !~ PLATFORMS
    raise ArgumentError, "Unsupported platform name #{name}"
  end
  super
end

Instance Method Details

#with_version_codenameString

Returns the platform string with the platform version as a codename. If no conversion is necessary then the original, unchanged platform String is returned.

Examples:

Platform.new(‘debian-7-xxx’).with_version_codename == ‘debian-wheezy-xxx’

Returns:

  • (String)

    the platform string with the platform version represented as a codename



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/beaker/platform.rb', line 45

def with_version_codename
  name, version, extra = self.split('-', 3)
  PLATFORM_VERSION_CODES.each_key do |platform|
    if name =~ /#{platform}/
      PLATFORM_VERSION_CODES[platform].each do |version_codename, version_number|
        #remove '.' from version number
        if version.delete('.') =~ /#{version_number}/
          version = version_codename
          break
        end
      end
      break
    end
  end
  [name, version, extra].join('-')
end

#with_version_numberString

Returns the platform string with the platform version as a number. If no conversion is necessary then the original, unchanged platform String is returned.

Examples:

Platform.new(‘debian-wheezy-xxx’).with_version_number == ‘debian-7-xxx’

Returns:

  • (String)

    the platform string with the platform version represented as a number



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/beaker/platform.rb', line 66

def with_version_number
  name, version, extra = self.split('-', 3)
  PLATFORM_VERSION_CODES.each_key do |platform|
    if name =~ /#{platform}/
      PLATFORM_VERSION_CODES[platform].each do |version_codename, version_number|
        if version =~ /#{version_codename}/
          version = version_number
          break
        end
      end
      break
    end
  end
  [name, version, extra].join('-')
end