Class: Zypper::Upgraderepo::RepositoryVariables

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

Overview

Calculate and apply the variables that can be declared within the repository metadata.

Constant Summary collapse

VARIABLE_PATH =
"/etc/zypp/vars.d"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version) ⇒ RepositoryVariables

Returns a new instance of RepositoryVariables.



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/zypper/upgraderepo/repository.rb', line 18

def initialize(version)
  @variables = {
    releasever_major: version.split(".")[0],
    releasever_minor: version.split(".")[1],
    releasever: version,
    basearch: VAR_ARCH,
    arch: VAR_CPU_ARCH
  }

  Dir.glob(File.join(self.class::VARIABLE_PATH, "*")).each do |i|
    @variables[File.basename(i).to_sym] = File.read(i).strip
  end
end

Instance Attribute Details

#variablesObject (readonly)

Returns the value of attribute variables.



16
17
18
# File 'lib/zypper/upgraderepo/repository.rb', line 16

def variables
  @variables
end

Instance Method Details

#apply(str) ⇒ Object



32
33
34
35
36
37
# File 'lib/zypper/upgraderepo/repository.rb', line 32

def apply(str)
  str.gsub(/\${?([a-zA-Z0-9_]+)}?/) do
    last = Regexp.last_match(1)
    @variables[last.to_sym] || "<Unknown var: $#{last}>"
  end
end