Class: Zypper::Upgraderepo::RepositoryList

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

Overview

Handle the repository collection.

Constant Summary collapse

REPOSITORY_PATH =
"/etc/zypp/repos.d"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, variables) ⇒ RepositoryList

Returns a new instance of RepositoryList.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/zypper/upgraderepo/repository.rb', line 48

def initialize(options, variables)
  @alias = options.alias
  @name = options.name
  @only_repo = options.only_repo
  @only_enabled = options.only_enabled
  @only_invalid = options.only_invalid
  @only_protocols = options.only_protocols
  @overrides = options.overrides
  @upgrade_options = { alias: options.alias, name: options.name }
  @list = []

  @variables = variables
  Dir.glob(File.join(self.class::REPOSITORY_PATH, "*.repo")).each do |i|
    r = Request.build(Repository.new(i, @variables), options.timeout)
    @list << r
  end
  @max_col = @list.max_by { |r| r.name.length }.name.length

  @list = @list.sort_by(&:alias).map.with_index(1) { |r, i| { num: i, repo: r } }

  @list.sort_by! { |x| x[:repo].send(options.sorting_by) } if options.sorting_by != :alias

  @only_repo = select_repos(@only_repo) unless @only_repo.nil?

  load_overrides(options.overrides_filename) if options.overrides_filename
end

Instance Attribute Details

#listObject (readonly)

Returns the value of attribute list.



46
47
48
# File 'lib/zypper/upgraderepo/repository.rb', line 46

def list
  @list
end

#max_colObject (readonly)

Returns the value of attribute max_col.



46
47
48
# File 'lib/zypper/upgraderepo/repository.rb', line 46

def max_col
  @max_col
end

Instance Method Details

#each_with_number(options = {}) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/zypper/upgraderepo/repository.rb', line 86

def each_with_number(options = {})
  only_repo = options[:only_repo].nil? ? @only_repo : options[:only_repo]
  only_enabled = options[:only_enabled].nil? ? @only_enabled : options[:only_enabled]
  only_invalid = options[:only_invalid].nil? ? @only_invalid : options[:only_invalid]
  only_protocols = options[:only_protocols].nil? ? @only_protocols : options[: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

Returns:

  • (Boolean)


75
76
77
# File 'lib/zypper/upgraderepo/repository.rb', line 75

def only_enabled?
  @only_enabled
end

#saveObject



102
103
104
105
106
# File 'lib/zypper/upgraderepo/repository.rb', line 102

def save
  @list.each do |i|
    i[:repo].save
  end
end

#upgrade!(version) ⇒ Object



79
80
81
82
83
84
# File 'lib/zypper/upgraderepo/repository.rb', line 79

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