Class: RepoMate::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/repomate/configuration.rb

Overview

Configuration class

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Init



10
11
12
13
14
# File 'lib/repomate/configuration.rb', line 10

def initialize
  @configfile = File.join(ENV['HOME'], '.repomate')

  configure(@configfile)
end

Instance Method Details

#configure(configfile) ⇒ Object

Loads configfile



17
18
19
20
21
22
23
# File 'lib/repomate/configuration.rb', line 17

def configure(configfile)
  filecontent = []

  filecontent = YAML::load_file(configfile) if File.exists?(configfile)

  merge(filecontent)
end

#merge(filecontent = nil) ⇒ Object

Merges configfile content with defaults



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/repomate/configuration.rb', line 26

def merge(filecontent=nil)
  config = {}

  defaults = {
    :rootdir       => '/var/lib/repomate/repository',
    :dpkg          => '/usr/bin/dpkg',
    :suites        => [ "lenny", "squeeze" ],
    :components    => [ "main", "contrib" ],
    :architectures => [ "all", "amd64" ],
    :origin        => 'Repository',
    :label         => 'Repository',
    :gpg           => false,
    :gpg_enable    => false, # obsolete in a while
    :gpg_email     => '[email protected]',
    :gpg_password  => 'secret'
  }

  unless filecontent.empty?
    defaults.each do |key, value|
      keysymbol = key.to_sym
      setter = "#{key}="

      if filecontent[keysymbol]
        config[keysymbol] = filecontent[keysymbol]
      else
        config[keysymbol] = value
      end
    end
  else
    config = defaults
  end

  config.each do |key, value|
    setter = "#{key}="

    self.class.send(:attr_accessor, key) unless respond_to?(setter)

    send setter, value
  end
end