Class: UsefulUtilities::RedhatRelease

Inherits:
Object
  • Object
show all
Defined in:
lib/useful_utilities/redhat_release.rb

Overview

Redhat releases utilities

Constant Summary collapse

LEGACY_DISTRO_TEMPLATE =
'centos%{major_version}'.freeze
VERSION_SEPARATOR =

this may change to “dot” and “hyphen” if we allow not only final releases(beta, custom git builds, etc)

'.'.freeze
VERSION_SEPARATOR_REGEXP =

regexp to match single “dot” character

Regexp.escape(VERSION_SEPARATOR).freeze
VERSION_REGEXP =
%r{              # /etc/redhat-release samples: "CentOS Linux release 7.1.1503 (Core)", "Red Hat Enterprise Linux Server release 7.2 (Maipo)"
  (?<=[[:space:]])                # positive lookbehind assertion: ensures that the preceding character matches single "space" character, but doesn't include this character in the matched text
  (?<major_version>[[:digit:]])   # :major_version named capture group; it matches single digits
  #{VERSION_SEPARATOR_REGEXP}     # regexp for separator of version parts
  (?<minor_version>[[:digit:]]+)  # :minor_version named capture group; it matches one or more sequential digits
  (?:                             # grouping without capturing; "monthstamp" version part don't exist for versions of Centos older then 7
    #{VERSION_SEPARATOR_REGEXP}   # regexp for separator of version parts
    (?<monthstamp>[[:digit:]]{4}) # :monthstamp named capture group; it matches 4 sequential digits
  )?                              # zero or one times quantifier(repetition metacharacter)
  (?=[[:space:]])                 # positive lookahead assertion: ensures that the following character matches single "space" character, but doesn't include this character in the matched text
}x.freeze
DEFAULT_VERSION_ARR =
[6, 0].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(release_string) ⇒ RedhatRelease

Returns a new instance of RedhatRelease.



25
26
27
# File 'lib/useful_utilities/redhat_release.rb', line 25

def initialize(release_string)
  @release_string = release_string.to_s
end

Instance Attribute Details

#release_stringObject (readonly)

Returns the value of attribute release_string.



23
24
25
# File 'lib/useful_utilities/redhat_release.rb', line 23

def release_string
  @release_string
end

Class Method Details

.legacy_distro(ver) ⇒ Object



33
34
35
# File 'lib/useful_utilities/redhat_release.rb', line 33

def self.legacy_distro(ver)
  LEGACY_DISTRO_TEMPLATE % { major_version: ver }
end

.major_version(*args) ⇒ Object



29
30
31
# File 'lib/useful_utilities/redhat_release.rb', line 29

def self.major_version(*args)
  new(*args).major_version
end

Instance Method Details

#major_versionObject



37
38
39
# File 'lib/useful_utilities/redhat_release.rb', line 37

def major_version
  version_arr[0]
end

#minor_versionObject



41
42
43
# File 'lib/useful_utilities/redhat_release.rb', line 41

def minor_version
  version_arr[1]
end

#monthstampObject



45
46
47
# File 'lib/useful_utilities/redhat_release.rb', line 45

def monthstamp
  version_arr[2]
end

#version_stringObject



49
50
51
# File 'lib/useful_utilities/redhat_release.rb', line 49

def version_string
  version_arr.join(VERSION_SEPARATOR)
end