Class: Zypper::Upgraderepo::Repository

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Repository

Returns a new instance of Repository.



61
62
63
64
65
66
# File 'lib/zypper/upgraderepo/repository.rb', line 61

def initialize(filename)
  @filename = filename
  @repo = IniParse.parse(File.read(filename))
  @key = get_key 
  @res = nil
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



59
60
61
# File 'lib/zypper/upgraderepo/repository.rb', line 59

def filename
  @filename
end

Instance Method Details

#aliasObject



96
97
98
# File 'lib/zypper/upgraderepo/repository.rb', line 96

def alias
  @key
end

#alias=(value) ⇒ Object



100
101
102
103
# File 'lib/zypper/upgraderepo/repository.rb', line 100

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

#available?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/zypper/upgraderepo/repository.rb', line 105

def available?
  ping.is_a?(Net::HTTPSuccess)
end

#enabled?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/zypper/upgraderepo/repository.rb', line 68

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

#evaluate_alternative(version) ⇒ Object



126
127
128
129
130
131
132
133
134
# File 'lib/zypper/upgraderepo/repository.rb', line 126

def evaluate_alternative(version)
  if url =~ /dl\.google\.com/
    return { url: '', message: 'Just Google security, use this repo anyway ;)'}
  elsif not_found?
    return traverse_url(URI(url.clone), version)
  elsif redirected?
    return { url: redirected_to, message: 'Redirected to:' }
  end
end

#nameObject



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

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

#name=(value) ⇒ Object



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

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

#not_found?Boolean

Returns:

  • (Boolean)


117
118
119
# File 'lib/zypper/upgraderepo/repository.rb', line 117

def not_found?
  ping.is_a?(Net::HTTPNotFound)
end

#priorityObject



84
85
86
# File 'lib/zypper/upgraderepo/repository.rb', line 84

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

#redirected?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/zypper/upgraderepo/repository.rb', line 109

def redirected?
  ping.is_a?(Net::HTTPRedirection)
end

#redirected_toObject



113
114
115
# File 'lib/zypper/upgraderepo/repository.rb', line 113

def redirected_to
  ping['location']
end

#saveObject

Raises:



121
122
123
124
# File 'lib/zypper/upgraderepo/repository.rb', line 121

def save
  raise InvalidPermissions, @filename unless File.writable? @filename
  @repo.save(@filename) 
end

#typeObject



72
73
74
# File 'lib/zypper/upgraderepo/repository.rb', line 72

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

#urlObject



88
89
90
# File 'lib/zypper/upgraderepo/repository.rb', line 88

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

#url=(value) ⇒ Object



92
93
94
# File 'lib/zypper/upgraderepo/repository.rb', line 92

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