steenzout-cfg 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.textile ADDED
@@ -0,0 +1,32 @@
1
+ h1. steenzout-cfg
2
+
3
+ Configuration management gem for steenzout packages which,
4
+ if the same convention is followed,
5
+ can be used for any other gems.
6
+
7
+
8
+ h2. convention
9
+
10
+ On your YAML configuration files, the gem name should be the first element.
11
+
12
+ <pre><code># sample.yaml
13
+ :gem1:
14
+ (...)
15
+ :property: value
16
+
17
+ :gem2:
18
+ (...)
19
+ :property: value
20
+ </pre><code>
21
+
22
+
23
+ h2. usage
24
+
25
+ <pre><code>require 'rubygems
26
+ require 'steenzout-cfg'
27
+
28
+ # load the configuration
29
+ Steenzout::ConfigurationManager.load 'configuration.yaml'
30
+
31
+ # access a specific gem configuration
32
+ config = Steenzout::ConfigurationManager.configuration_for_gem 'steenzout-cfg'</code></pre>
@@ -0,0 +1,51 @@
1
+ module Steenzout
2
+
3
+ # Class to hold gem configurations.
4
+ class ConfigurationManager
5
+
6
+ @@loaded_configurations = {}
7
+ @@configurations = nil
8
+
9
+ # Loads the configuration from the given file.
10
+ # As convention, the configuration file should have as top symbol the gem name.
11
+ #
12
+ # Example:
13
+ # :steenzout-cfg:
14
+ # :log: 'log/development.log'
15
+ #
16
+ # Warning: loading a configuration file which hold configurations for a previous loaded gem,
17
+ # will cause the previous configuration to be lost.
18
+ #
19
+ #
20
+ # @param filename: the file to load the configuration.
21
+ #
22
+ def self.load filename
23
+
24
+ raise ArgumentError, "File #{filename} does not exist!" if !File.exist? filename
25
+
26
+ if @@configurations.nil?
27
+ # load configuration
28
+ @@configurations = YAML.load_file(filename)
29
+ else
30
+ # merge existing configurations
31
+ YAML.load_file(filename).each {|key, value|
32
+ @@configurations[key] = value
33
+ }
34
+ end
35
+
36
+ # TODO: for each gem name, store from which file the configuration was loaded...
37
+
38
+ end
39
+
40
+
41
+
42
+ # Returns the configuration for the given gem.
43
+ #
44
+ # @param name: the name of the gem.
45
+ #
46
+ def self.configuration_for_gem name
47
+ @@configurations[:"#{name}"]
48
+ end
49
+
50
+ end
51
+ end
@@ -0,0 +1,7 @@
1
+ require 'YAML'
2
+
3
+ module Steenzout
4
+
5
+ autoload :ConfigurationManager, "#{File.dirname(__FILE__)}/cfg/manager"
6
+
7
+ end
@@ -0,0 +1,51 @@
1
+ require 'test/unit'
2
+ require 'lib/steenzout-cfg'
3
+
4
+
5
+
6
+ class TestConfigurationManager < Test::Unit::TestCase
7
+
8
+ def setup
9
+
10
+ Steenzout::ConfigurationManager.load 'test/simple.yaml'
11
+
12
+ end
13
+
14
+
15
+
16
+ def test_configuration_for_gem
17
+
18
+ config = Steenzout::ConfigurationManager.configuration_for_gem 'steenzout-cfg'
19
+ assert_equal({:property => 'value1'}, config)
20
+
21
+ end
22
+
23
+
24
+
25
+ def test_load
26
+
27
+ # 1. loading another file with same gem configuration
28
+ Steenzout::ConfigurationManager.load 'test/another.yaml'
29
+
30
+ config = Steenzout::ConfigurationManager.configuration_for_gem 'steenzout-cfg'
31
+ assert_equal({:property => 'value2'}, config)
32
+
33
+
34
+ # 2. loading another file with no duplicate configuration
35
+ Steenzout::ConfigurationManager.load 'test/yetanother.yaml'
36
+
37
+ config = Steenzout::ConfigurationManager.configuration_for_gem 'steenzout-cfg'
38
+ assert_equal({:property => 'value2'}, config)
39
+
40
+ config = Steenzout::ConfigurationManager.configuration_for_gem 'steenzout-dao'
41
+ assert_equal({:property => 'value3'}, config)
42
+
43
+
44
+ # 3. loading from inexistent file
45
+ assert_raises ArgumentError do
46
+ Steenzout::ConfigurationManager.load 'test/inexistent.yaml'
47
+ end
48
+
49
+ end
50
+
51
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: steenzout-cfg
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - steenzout
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-02-14 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: |
23
+ This gem provides configuration management functionality through a simple convention.
24
+
25
+ email:
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - README.textile
32
+ files:
33
+ - lib/cfg/manager.rb
34
+ - lib/steenzout-cfg.rb
35
+ - README.textile
36
+ - test/unit/cfg/manager_test.rb
37
+ has_rdoc: true
38
+ homepage: https://github.com/steenzout/steenzout-cfg
39
+ licenses: []
40
+
41
+ post_install_message:
42
+ rdoc_options: []
43
+
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ hash: 3
52
+ segments:
53
+ - 0
54
+ version: "0"
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ requirements: []
65
+
66
+ rubyforge_project:
67
+ rubygems_version: 1.5.0
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: Steenzout configuration management gem.
71
+ test_files:
72
+ - test/unit/cfg/manager_test.rb