<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>test/override_with.yml</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -21,15 +21,21 @@ class ApplicationConfiguration
   def reload!
     conf1 = load_conf_file(@conf_path_1)
     conf2 = load_conf_file(@conf_path_2)
-    conf  = recursive_merge(conf1, conf2)
-    @config = ClosedStruct.r_new(conf)
+    @config_hash  = recursive_merge(conf1, conf2)
+    @config = ClosedStruct.r_new(@config_hash)
   end
   
-  def use_environment!(environment)
-    if @config.respond_to?(environment)
-      @config = @config.send(environment)
-    else
-      raise ArgumentError, &quot;environment doesn't exist in app config: #{environment}&quot;
+  def use_environment!(environment, options = {})
+    raise ArgumentError, &quot;environment doesn't exist in app config: #{environment}&quot; \
+      unless @config_hash.has_key?(environment.to_s)
+    
+    @config_hash = @config_hash[environment.to_s]
+    @config = @config.send(environment)
+    
+    if options[:override_with] and File.exist?(options[:override_with])
+      overriding_config = load_conf_file(options[:override_with])
+      @config_hash = recursive_merge(@config_hash, overriding_config)
+      @config = ClosedStruct.r_new(@config_hash)
     end
   end
   </diff>
      <filename>lib/app_config.rb</filename>
    </modified>
    <modified>
      <diff>@@ -75,4 +75,31 @@ class AppConfigTest &lt; Test::Unit::TestCase
     assert_raise(NoMethodError){ config.emails.support }
   end
   
+  def test_use_environment_override_with
+    config = ApplicationConfiguration.new('test/environments.yml')
+    config.use_environment!(&quot;development&quot;, :override_with =&gt; &quot;test/override_with.yml&quot;)
+    assert_equal 10, config.size
+    assert_equal &quot;over.com&quot;, config.section.servers[0].name
+    assert_equal &quot;ride.com&quot;, config.section.servers[1].name
+    assert_equal &quot;google.com&quot;, config.server
+    assert_equal 6, config.computed
+    assert_equal &quot;webmaster@domain.com&quot;, config.emails.webmaster
+    assert_equal &quot;feedback@domain.com&quot;, config.emails.feedback
+    assert_raise(NoMethodError){ config.emails.support }
+  end
+  
+  def test_use_environment_override_with_no_file
+    config = ApplicationConfiguration.new('test/environments.yml')
+    config.use_environment!(&quot;development&quot;, :override_with =&gt; &quot;test/non_existant.yml&quot;)
+    assert_equal 2, config.size
+    assert_equal &quot;google.com&quot;, config.server
+    assert_equal 6, config.computed
+    assert_equal 3, config.section.size
+    assert_equal &quot;yahoo.com&quot;, config.section.servers[0].name
+    assert_equal &quot;amazon.com&quot;, config.section.servers[1].name
+    assert_equal &quot;webmaster@domain.com&quot;, config.emails.webmaster
+    assert_equal &quot;feedback@domain.com&quot;, config.emails.feedback
+    assert_raise(NoMethodError){ config.emails.support }
+  end
+  
 end</diff>
      <filename>test/app_config_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>01ecf27f141973e1f5a7bcc1668c00339dea8e6f</id>
    </parent>
  </parents>
  <author>
    <name>cjbottaro</name>
    <email>cjbottaro@alumni.cs.utexas.edu</email>
  </author>
  <url>http://github.com/cjbottaro/app_config/commit/763359395fc622dd0beb8258b3f7c77b630f6d49</url>
  <id>763359395fc622dd0beb8258b3f7c77b630f6d49</id>
  <committed-date>2009-09-08T10:32:25-07:00</committed-date>
  <authored-date>2009-09-08T10:32:25-07:00</authored-date>
  <message>Issue #2 - implemented :override_with option for #use_environment!</message>
  <tree>11f01302245ce7e6adcf13e82de388a44dfec225</tree>
  <committer>
    <name>cjbottaro</name>
    <email>cjbottaro@alumni.cs.utexas.edu</email>
  </committer>
</commit>
