Class: Zypper::Upgraderepo::Repository

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

Overview

Single repository class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, variables) ⇒ Repository

Returns a new instance of Repository.



172
173
174
175
176
177
178
179
180
# File 'lib/zypper/upgraderepo/repository.rb', line 172

def initialize(filename, variables)
  @filename = filename
  @repo = IniParse.parse(File.read(filename))
  @key = read_key
  @old_url = nil
  @old_name = nil
  @old_alias = nil
  resolve_variables!(variables)
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



170
171
172
# File 'lib/zypper/upgraderepo/repository.rb', line 170

def filename
  @filename
end

#old_aliasObject (readonly)

Returns the value of attribute old_alias.



170
171
172
# File 'lib/zypper/upgraderepo/repository.rb', line 170

def old_alias
  @old_alias
end

#old_nameObject (readonly)

Returns the value of attribute old_name.



170
171
172
# File 'lib/zypper/upgraderepo/repository.rb', line 170

def old_name
  @old_name
end

#old_urlObject (readonly)

Returns the value of attribute old_url.



170
171
172
# File 'lib/zypper/upgraderepo/repository.rb', line 170

def old_url
  @old_url
end

Instance Method Details

#aliasObject



226
227
228
# File 'lib/zypper/upgraderepo/repository.rb', line 226

def alias
  @key
end

#alias=(value) ⇒ Object



230
231
232
233
# File 'lib/zypper/upgraderepo/repository.rb', line 230

def alias=(value)
  @repo = IniParse.parse(@repo.to_ini.sub(/\[[^\]]+\]/, "[#{value}]"))
  @key = read_key
end

#enable!(value = nil) ⇒ Object



186
187
188
# File 'lib/zypper/upgraderepo/repository.rb', line 186

def enable!(value = nil)
  @repo[@key]["enabled"] = (value || true).to_s =~ /true|1|yes/i ? 1 : 0
end

#enabled?Boolean

Returns:

  • (Boolean)


182
183
184
# File 'lib/zypper/upgraderepo/repository.rb', line 182

def enabled?
  @repo[@key]["enabled"].to_i == 1
end

#nameObject



194
195
196
# File 'lib/zypper/upgraderepo/repository.rb', line 194

def name
  @repo[@key]["name"] || @key
end

#name=(value) ⇒ Object



198
199
200
# File 'lib/zypper/upgraderepo/repository.rb', line 198

def name=(value)
  @repo[@key]["name"] = value
end

#priorityObject



202
203
204
# File 'lib/zypper/upgraderepo/repository.rb', line 202

def priority
  @repo[@key]["priority"] || 99
end

#protocolObject



214
215
216
# File 'lib/zypper/upgraderepo/repository.rb', line 214

def protocol
  URI(url.to_s).scheme
end

#saveObject



250
251
252
253
254
255
256
257
# File 'lib/zypper/upgraderepo/repository.rb', line 250

def save
  raise InvalidWritePermissions, @filename unless File.writable? @filename

  process, pid = libzypp_process
  raise SystemUpdateRunning, { pid: pid, process: process } if pid

  @repo.save(@filename)
end

#typeObject



190
191
192
# File 'lib/zypper/upgraderepo/repository.rb', line 190

def type
  @repo[@key]["type"]
end

#unversioned?Boolean

Returns:

  • (Boolean)


218
219
220
# File 'lib/zypper/upgraderepo/repository.rb', line 218

def unversioned?
  (url =~ /\d\d\.\d/).nil?
end

#upgrade!(version, args = {}) ⇒ Object



235
236
237
238
239
240
241
242
243
244
# File 'lib/zypper/upgraderepo/repository.rb', line 235

def upgrade!(version, args = {})
  @old_url ||= url
  @old_alias ||= self.alias
  @old_name ||= name

  self.url = (args[:url_override] || url.gsub(/\d\d\.\d/, version))

  self.alias = self.alias.gsub(/\d\d\.\d/, version) if args[:alias]
  self.name = name.gsub(/\d\d\.\d/, version) if args[:name]
end

#upgraded?(item = :url) ⇒ Boolean

Returns:

  • (Boolean)


246
247
248
# File 'lib/zypper/upgraderepo/repository.rb', line 246

def upgraded?(item = :url)
  !send("old_#{item}").nil? && (send("old_#{item}") != send(item))
end

#urlObject



206
207
208
# File 'lib/zypper/upgraderepo/repository.rb', line 206

def url
  @repo[@key]["baseurl"]
end

#url=(value) ⇒ Object



210
211
212
# File 'lib/zypper/upgraderepo/repository.rb', line 210

def url=(value)
  @repo[@key]["baseurl"] = value
end

#versioned?Boolean

Returns:

  • (Boolean)


222
223
224
# File 'lib/zypper/upgraderepo/repository.rb', line 222

def versioned?
  !unversioned?
end