Katello/katello — pull request #1049 by pitr-ch (2012-11-13 10:20:23+00:00)
Title: configuration clean up 

This PR is **not ready to be merged**. I am opening it for comments, because it introduces more changes than I anticipated.

#### Highlights

* single access point to configuration
* no ENV usage in code (precessed by configuration)
* configuration is not dependent to any gem (can be used even in Gemfile)
* more strict, catches misconfiguration earlier
* cleaner implementation

#### TODO

* test build
* test katello-configure

#### Commit message

clean up configuration

As a developer, I would like to katello.yml is always correctly loaded
As a developer, I would like to katello.yml be loaded only once
As a developer, I would like to config/katello.yml be preferred before /etc/katello/katello.yml
As a developer, I would like to katello.yml not to be in git repository.
remove database.yml
centralize Katello configuration
remove ENV usage from code, use configuration instead

#### Copied from code documentation:

Katello::Configuration module contains all necessary code for Katello configuration.
Configuration is not dependent on any gem which allows loading configuration very early (even before Rails). Therefore this configuration can be used anywhere (Gemfile, boot scripts, etc.)

Configuration access points are methods #config and #early_config, see method documentation.
There are shortcuts defined: `Katello.config` and `Katello.early_config`

Configuration is represented with tree-like-structure defined with Configuration::Node. Node has minimal Hash-like interface. Node is more strict than Hash. Differences:

* If undefined key is accessed an error NoKey is raised (keys with nil values has to be defined explicitly).
* Keys can be accessed by methods. `config.host` is equivalent to `config[:host]`
* All keys has to be Symbols, otherwise you get an ArgumentError

AppConfig will work for now, but warning is printed to `$stderr`.

Some examples

# create by a Hash which is converted to Node instance
irb> n = Katello::Configuration::Node.new 'a' => nil
=> #nil}>

# assign a value, also converted
irb> n[:a] = {'a' => 12}
=> {:a=>12}
irb> n
=> ##12}>}>

# accessing a key
irb> n['a']
ArgumentError: "a" should be a Symbol
irb> n[:a]
=> #12}>
irb> n[:not]
Katello::Configuration::Node::NoKey: missing key 'not' in configuration

# sooports deep_merge and #to_hash
irb> n.deep_merge!('a' => {:b => 34})
=> ##12, :b=>34}>}>
irb> n.to_hash
=> {:a=>{:a=>12, :b=>34}}