Class: Zypper::Upgraderepo::OsRelease

Inherits:
Object
  • Object
show all
Defined in:
lib/zypper/upgraderepo/os_release.rb

Constant Summary collapse

OS_VERSIONS =
['13.1', '13.2', '42.1', '42.2', '42.3', '15.0', '15.1', '15.2', '15.3', '15.4']
UNSTABLE_VERSION =
'15.5'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ OsRelease

Returns a new instance of OsRelease.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/zypper/upgraderepo/os_release.rb', line 15

def initialize(options)

  if options.allow_unstable
    raise NoUnstableVersionAvailable if UNSTABLE_VERSION.empty?
    OS_VERSIONS << UNSTABLE_VERSION
    @unstable = true
  end

  fname = if File.exist? '/etc/os-release'
            '/etc/os-release'
          elsif File.exist? '/etc/SuSE-release'
            '/etc/SuSE-release'
          else
            raise ReleaseFileNotFound
          end
  @release = IniParse.parse(File.read(fname))
  @current_idx = OS_VERSIONS.index(@release['__anonymous__']['VERSION'].delete('"'))

  if options.version
    raise InvalidVersion, options.version unless OS_VERSIONS.include?(options.version)
    @custom = options.version
  end
end

Instance Attribute Details

#customObject (readonly)

Returns the value of attribute custom.



9
10
11
# File 'lib/zypper/upgraderepo/os_release.rb', line 9

def custom
  @custom
end

#unstableObject (readonly)

Returns the value of attribute unstable.



9
10
11
# File 'lib/zypper/upgraderepo/os_release.rb', line 9

def unstable
  @unstable
end

Instance Method Details

#currentObject



39
40
41
# File 'lib/zypper/upgraderepo/os_release.rb', line 39

def current
  OS_VERSIONS[@current_idx]
end

#current?(version) ⇒ Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/zypper/upgraderepo/os_release.rb', line 91

def current?(version)
  OS_VERSIONS.index(version) == @current_idx
end

#first?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/zypper/upgraderepo/os_release.rb', line 83

def first?
  @current_idx == 0
end

#fullnameObject



63
64
65
# File 'lib/zypper/upgraderepo/os_release.rb', line 63

def fullname
  @release['__anonymous__']['PRETTY_NAME'].gsub(/"/, '')
end

#lastObject



43
44
45
# File 'lib/zypper/upgraderepo/os_release.rb', line 43

def last
  OS_VERSIONS[-1]
end

#last?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/zypper/upgraderepo/os_release.rb', line 79

def last?
  @current_idx == (OS_VERSIONS.count - 1)
end

#newerObject



71
72
73
74
75
76
77
# File 'lib/zypper/upgraderepo/os_release.rb', line 71

def newer
  if seniority > 0
    OS_VERSIONS[@current_idx.next..-1]
  else
    []
  end
end

#nextObject



47
48
49
50
51
52
53
# File 'lib/zypper/upgraderepo/os_release.rb', line 47

def next
  unless last?
    OS_VERSIONS[@current_idx.next]
  else
    nil
  end
end

#previousObject



55
56
57
58
59
60
61
# File 'lib/zypper/upgraderepo/os_release.rb', line 55

def previous
  unless first?
    OS_VERSIONS[@current_idx.pred]
  else
    nil
  end
end

#seniorityObject



67
68
69
# File 'lib/zypper/upgraderepo/os_release.rb', line 67

def seniority
  OS_VERSIONS.count - @current_idx.next
end

#valid?(version) ⇒ Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/zypper/upgraderepo/os_release.rb', line 87

def valid?(version)
  OS_VERSIONS.include? version
end