Class: Beaker::Platform
- Inherits:
-
String
- Object
- String
- Beaker::Platform
- 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", "lucid" => "1004", }, }
Instance Attribute Summary collapse
-
#arch ⇒ Object
readonly
A string with the cpu architecture of the platform.
-
#codename ⇒ Object
readonly
A string with the codename of the platform+version, nil on platforms without codenames.
-
#variant ⇒ Object
readonly
A string with the name of the platform.
-
#version ⇒ Object
readonly
A string with the version number of the platform.
Instance Method Summary collapse
-
#initialize(name) ⇒ Platform
constructor
Creates the Platform object.
-
#to_array ⇒ Object
Returns array of attributes to allow single line assignment to local variables in DSL and test case methods.
-
#with_version_codename ⇒ String
Returns the platform string with the platform version as a codename.
-
#with_version_number ⇒ String
Returns the platform string with the platform version as a number.
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:
-
osx
-
centos
-
fedora
-
debian
-
oracle
-
redhat
-
scientific
-
sles
-
ubuntu
-
windows
-
solaris
-
aix
-
el
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/beaker/platform.rb', line 51 def initialize(name) if name !~ PLATFORMS raise ArgumentError, "Unsupported platform name #{name}" end super @variant, version, @arch = self.split('-', 3) codename_version_hash = PLATFORM_VERSION_CODES[@variant.to_sym] @version = version @codename = nil if codename_version_hash if codename_version_hash[version] @codename = version @version = codename_version_hash[version] else version = version.delete('.') version_codename_hash = codename_version_hash.invert @codename = version_codename_hash[version] end end end |
Instance Attribute Details
#arch ⇒ Object (readonly)
A string with the cpu architecture of the platform.
33 34 35 |
# File 'lib/beaker/platform.rb', line 33 def arch @arch end |
#codename ⇒ Object (readonly)
A string with the codename of the platform+version, nil on platforms without codenames.
30 31 32 |
# File 'lib/beaker/platform.rb', line 30 def codename @codename end |
#variant ⇒ Object (readonly)
A string with the name of the platform.
23 24 25 |
# File 'lib/beaker/platform.rb', line 23 def variant @variant end |
#version ⇒ Object (readonly)
A string with the version number of the platform.
26 27 28 |
# File 'lib/beaker/platform.rb', line 26 def version @version end |
Instance Method Details
#to_array ⇒ Object
Returns array of attributes to allow single line assignment to local variables in DSL and test case methods.
78 79 80 |
# File 'lib/beaker/platform.rb', line 78 def to_array return @variant, @version, @arch, @codename end |
#with_version_codename ⇒ String
Returns the platform string with the platform version as a codename. If no conversion is necessary then the original, unchanged platform String is returned.
86 87 88 89 90 91 92 |
# File 'lib/beaker/platform.rb', line 86 def with_version_codename version_array = [@variant, @version, @arch] if @codename version_array = [@variant, @codename, @arch] end return version_array.join('-') end |
#with_version_number ⇒ String
Returns the platform string with the platform version as a number. If no conversion is necessary then the original, unchanged platform String is returned.
98 99 100 |
# File 'lib/beaker/platform.rb', line 98 def with_version_number [@variant, @version, @arch].join('-') end |