Class: Zypper::Upgraderepo::RepositoryList
- Inherits:
-
Object
- Object
- Zypper::Upgraderepo::RepositoryList
- Defined in:
- lib/zypper/upgraderepo/repository.rb
Constant Summary collapse
- REPOSITORY_PATH =
'/etc/zypp/repos.d'
Instance Attribute Summary collapse
-
#list ⇒ Object
readonly
Returns the value of attribute list.
-
#max_col ⇒ Object
readonly
Returns the value of attribute max_col.
Instance Method Summary collapse
- #each_with_number(options = {}) ⇒ Object
-
#initialize(options) ⇒ RepositoryList
constructor
A new instance of RepositoryList.
- #only_enabled? ⇒ Boolean
- #resolve_variables!(version) ⇒ Object
- #save ⇒ Object
- #upgrade!(version) ⇒ Object
Constructor Details
#initialize(options) ⇒ RepositoryList
Returns a new instance of RepositoryList.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/zypper/upgraderepo/repository.rb', line 13 def initialize() @alias = .alias @name = .name @only_repo = .only_repo @only_enabled = .only_enabled @only_invalid = .only_invalid @only_protocols = .only_protocols @overrides = .overrides @upgrade_options = {alias: .alias, name: .name} @list = [] @cpu_arch, @arch = `rpm --eval "%cpu_arch;%_arch"`.tr("\n", '').split(';') Dir.glob(File.join(self.class::REPOSITORY_PATH, '*.repo')).each do |i| r = Request.build(Repository.new(i), .timeout) @list << r end @max_col = @list.max_by { |r| r.name.length }.name.length @list = @list.sort_by { |r| r.alias }.map.with_index(1) { |r, i| { num: i, repo: r } } @list.sort_by! { |x| x[:repo].send(.sort_by) } if .sort_by != :alias @only_repo = select_repos(@only_repo) unless @only_repo.nil? load_overrides(.overrides_filename) if .overrides_filename end |
Instance Attribute Details
#list ⇒ Object (readonly)
Returns the value of attribute list.
11 12 13 |
# File 'lib/zypper/upgraderepo/repository.rb', line 11 def list @list end |
#max_col ⇒ Object (readonly)
Returns the value of attribute max_col.
11 12 13 |
# File 'lib/zypper/upgraderepo/repository.rb', line 11 def max_col @max_col end |
Instance Method Details
#each_with_number(options = {}) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/zypper/upgraderepo/repository.rb', line 51 def each_with_number( = {}) only_repo = [:only_repo].nil? ? @only_repo : [:only_repo] only_enabled = [:only_enabled].nil? ? @only_enabled : [:only_enabled] only_invalid = [:only_invalid].nil? ? @only_invalid : [:only_invalid] only_protocols = [:only_protocols].nil? ? @only_protocols : [:only_protocols] @list.each do |x| next if only_repo && !only_repo.include?(x[:num]) next if only_enabled && !x[:repo].enabled? next if only_invalid && x[:repo].available? next if only_protocols && (!only_protocols.include?(x[:repo].protocol)) yield x[:repo], x[:num] if block_given? end end |
#only_enabled? ⇒ Boolean
40 41 42 |
# File 'lib/zypper/upgraderepo/repository.rb', line 40 def only_enabled? @only_enabled end |
#resolve_variables!(version) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/zypper/upgraderepo/repository.rb', line 67 def resolve_variables!(version) each_with_number do |r| if r.url =~ /\$/ r.url = (r.url, version) end r.name = (r.name, version) r.alias = (r.alias, version) end self end |
#save ⇒ Object
79 80 81 82 83 |
# File 'lib/zypper/upgraderepo/repository.rb', line 79 def save @list.each do |i| i[:repo].save end end |
#upgrade!(version) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/zypper/upgraderepo/repository.rb', line 44 def upgrade!(version) each_with_number(only_invalid: false) do |repo, num| repo.upgrade! version, @upgrade_options.merge(url_override: @overrides[num]) repo.cache! end end |