Class: RankMirror::Config
- Inherits:
-
Object
- Object
- RankMirror::Config
- Defined in:
- lib/rankmirror/config.rb
Instance Method Summary collapse
-
#initialize(options) ⇒ Config
constructor
A new instance of Config.
- #parse(config, args) ⇒ Object
- #path ⇒ Object
- #save(array, header) ⇒ Object
Constructor Details
#initialize(options) ⇒ Config
Returns a new instance of Config.
8 9 10 11 12 13 14 |
# File 'lib/rankmirror/config.rb', line 8 def initialize() @options = @name = @options.os @file = @name + ".mirrorlist" @systempath = File.(File.join(File.dirname(__FILE__),"mirrorlists")) @localpath = ENV['HOME'] + "/.rankmirror/" end |
Instance Method Details
#parse(config, args) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rankmirror/config.rb', line 47 def parse(config,args) f = open(config) mirrors = f.readlines.map!{|l| unless l.start_with?("#") elements = l.strip.split("\t") mirror = OpenStruct.new args.each_with_index {|arg,index| mirror[arg] = elements[index] } mirror end }.compact f.close return mirrors end |
#path ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rankmirror/config.rb', line 16 def path if File.exist?(systemconfig) && File.readable?(systemconfig) if File.exist?(localconfig) m = merge(systemconfig,localconfig) write(m,localconfig,@options.keys) localconfig else systemconfig end else if File.exist?(localconfig) localconfig else nil end end end |
#save(array, header) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rankmirror/config.rb', line 34 def save(array,header) FileUtils.mkdir_p @localpath unless File.directory?(@localpath) mirrors_array = array.map! do |uri| mirror = RankMirror::Status.new(uri,@name).get mirror.name = URI.parse(uri).host if mirror.name.nil? mirror.continent = "world" if ["opensuse","packman"].include?(@name) mirror.country = "world" mirror.http = uri mirror end write(mirrors_array,localconfig,header) end |