class RepoMate::Configuration

Configuration class

Public Class Methods

new() click to toggle source

Init

# File lib/repomate/configuration.rb, line 10
def initialize
  @configfile = File.join(ENV['HOME'], '.repomate')

  configure(@configfile)
end

Public Instance Methods

configure(configfile) click to toggle source

Loads configfile

# 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) click to toggle source

Merges configfile content with defaults

# 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     => 'someone@example.net',
    :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