cjbottaro-app_config 1.1.0 → 1.2.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.
@@ -1,4 +1,4 @@
1
1
  ---
2
- :minor: 1
3
- :major: 1
4
2
  :patch: 0
3
+ :major: 1
4
+ :minor: 2
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{app_config}
8
- s.version = "1.1.0"
8
+ s.version = "1.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Christopher J Bottaro"]
12
- s.date = %q{2009-08-28}
12
+ s.date = %q{2009-09-08}
13
13
  s.description = %q{Application level configuration that supports YAML config file, inheritance, ERB, and object member notation.}
14
14
  s.email = %q{cjbottaro@alumni.cs.utexas.edu}
15
15
  s.extra_rdoc_files = [
@@ -33,12 +33,14 @@ Gem::Specification.new do |s|
33
33
  "test/empty1.yml",
34
34
  "test/empty2.yml",
35
35
  "test/environments.yml",
36
+ "test/override_with.yml",
36
37
  "uninstall.rb"
37
38
  ]
39
+ s.has_rdoc = true
38
40
  s.homepage = %q{http://github.com/cjbottaro/app_config}
39
41
  s.rdoc_options = ["--charset=UTF-8"]
40
42
  s.require_paths = ["lib"]
41
- s.rubygems_version = %q{1.3.3}
43
+ s.rubygems_version = %q{1.3.2}
42
44
  s.summary = %q{Application level configuration.}
43
45
  s.test_files = [
44
46
  "test/app_config_test.rb",
@@ -21,15 +21,21 @@ class ApplicationConfiguration
21
21
  def reload!
22
22
  conf1 = load_conf_file(@conf_path_1)
23
23
  conf2 = load_conf_file(@conf_path_2)
24
- conf = recursive_merge(conf1, conf2)
25
- @config = ClosedStruct.r_new(conf)
24
+ @config_hash = recursive_merge(conf1, conf2)
25
+ @config = ClosedStruct.r_new(@config_hash)
26
26
  end
27
27
 
28
- def use_environment!(environment)
29
- if @config.respond_to?(environment)
30
- @config = @config.send(environment)
31
- else
32
- raise ArgumentError, "environment doesn't exist in app config: #{environment}"
28
+ def use_environment!(environment, options = {})
29
+ raise ArgumentError, "environment doesn't exist in app config: #{environment}" \
30
+ unless @config_hash.has_key?(environment.to_s)
31
+
32
+ @config_hash = @config_hash[environment.to_s]
33
+ @config = @config.send(environment)
34
+
35
+ if options[:override_with] and File.exist?(options[:override_with])
36
+ overriding_config = load_conf_file(options[:override_with])
37
+ @config_hash = recursive_merge(@config_hash, overriding_config)
38
+ @config = ClosedStruct.r_new(@config_hash)
33
39
  end
34
40
  end
35
41
 
@@ -75,4 +75,31 @@ class AppConfigTest < Test::Unit::TestCase
75
75
  assert_raise(NoMethodError){ config.emails.support }
76
76
  end
77
77
 
78
+ def test_use_environment_override_with
79
+ config = ApplicationConfiguration.new('test/environments.yml')
80
+ config.use_environment!("development", :override_with => "test/override_with.yml")
81
+ assert_equal 10, config.size
82
+ assert_equal "over.com", config.section.servers[0].name
83
+ assert_equal "ride.com", config.section.servers[1].name
84
+ assert_equal "google.com", config.server
85
+ assert_equal 6, config.computed
86
+ assert_equal "webmaster@domain.com", config.emails.webmaster
87
+ assert_equal "feedback@domain.com", config.emails.feedback
88
+ assert_raise(NoMethodError){ config.emails.support }
89
+ end
90
+
91
+ def test_use_environment_override_with_no_file
92
+ config = ApplicationConfiguration.new('test/environments.yml')
93
+ config.use_environment!("development", :override_with => "test/non_existant.yml")
94
+ assert_equal 2, config.size
95
+ assert_equal "google.com", config.server
96
+ assert_equal 6, config.computed
97
+ assert_equal 3, config.section.size
98
+ assert_equal "yahoo.com", config.section.servers[0].name
99
+ assert_equal "amazon.com", config.section.servers[1].name
100
+ assert_equal "webmaster@domain.com", config.emails.webmaster
101
+ assert_equal "feedback@domain.com", config.emails.feedback
102
+ assert_raise(NoMethodError){ config.emails.support }
103
+ end
104
+
78
105
  end
@@ -0,0 +1,3 @@
1
+ size: 10
2
+ section:
3
+ servers: [ {name: over.com}, {name: ride.com} ]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cjbottaro-app_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher J Bottaro
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-28 00:00:00 -07:00
12
+ date: 2009-09-08 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -39,8 +39,9 @@ files:
39
39
  - test/empty1.yml
40
40
  - test/empty2.yml
41
41
  - test/environments.yml
42
+ - test/override_with.yml
42
43
  - uninstall.rb
43
- has_rdoc: false
44
+ has_rdoc: true
44
45
  homepage: http://github.com/cjbottaro/app_config
45
46
  post_install_message:
46
47
  rdoc_options: