<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>lib/core_ext/class.rb</filename>
    </added>
    <added>
      <filename>lib/rails_ext/activerecord/base.rb</filename>
    </added>
    <added>
      <filename>test/abstract_unit.rb</filename>
    </added>
    <added>
      <filename>test/active_record_test.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -3,9 +3,11 @@
 require File.dirname(__FILE__) + '/lib/core_ext/proc_source'
 require File.dirname(__FILE__) + '/lib/background'
 require File.dirname(__FILE__) + '/lib/core_ext/background'
+require File.dirname(__FILE__) + '/lib/core_ext/class'
 Dir.glob(File.dirname(__FILE__) + '/lib/core_ext/handlers/*.rb').each do |handler|
   require handler
 end
 Dir.glob(File.dirname(__FILE__) + '/lib/core_ext/error_reporters/*.rb').each do |reporter|
   require reporter
 end
+require File.dirname(__FILE__) + '/lib/rails_ext/activerecord/base'</diff>
      <filename>init.rb</filename>
    </modified>
    <modified>
      <diff>@@ -20,8 +20,33 @@ module Background #:nodoc:
     end
     
     def self.load(configuration)
-      loaded_config = ((config[RAILS_ENV] || {})[configuration] || {})
-      default_config.merge(loaded_config.symbolize_keys || {})
+      if configuration.blank?
+        default_config
+      else
+        loaded_config = ((config[RAILS_ENV] || {})[configuration] || {})
+        default_config.merge(loaded_config.symbolize_keys || {})
+      end
+    end
+  end
+  
+  mattr_accessor :disabled
+  self.disabled = false
+  
+  def self.disable!
+    Background.disabled = true
+  end
+  
+  def self.enable!
+    Background.disabled = false
+  end
+  
+  def self.disable(&amp;block)
+    value = Background.disabled
+    begin
+      Background.disable!
+      yield
+    ensure
+      Background.disabled = value
     end
   end
 end</diff>
      <filename>lib/background.rb</filename>
    </modified>
    <modified>
      <diff>@@ -15,7 +15,7 @@ module Kernel
   #      end
   #
   #      # execute all calls to FactorialClass#factorial in the background
-  #      background :factorial, :params =&gt; ['number']
+  #      background :factorial
   #    end
   #
   # === Execute a block in the background.
@@ -69,10 +69,6 @@ module Kernel
   #           element of the array may be a Symbol or a hash with one element. If it is a hash, the key
   #           is the handler name, and the value contains configuration options for the handler.
   #
-  # params:: Parameter names of the method to decorate. These parameter names must match the parameter
-  #          names of the original method, that is decorated. This option is ignored, when a block is
-  #          given.
-  #
   # locals:: A Hash containing name-value-pairs of local variables that need to be accessible to the
   #          block when it is run in the background. This option is ignored when a method is decorated.
   #
@@ -130,35 +126,22 @@ module Kernel
   #   serialized and can be referenced in the block using the self keyword.
   def background(*args, &amp;block)
     if args.first.is_a?(Symbol) &amp;&amp; self.is_a?(Class)
-      method = args.shift
-      options = args.first || {}
-      params = options.delete(:params) || []
-      # handler = [options.delete(:handler)].flatten
-
-      alias_method_chain method, :background do |aliased_target, punctuation|
-        self.class_eval %{
-          def #{method}_with_background#{punctuation}(#{params.join(', ')})
-            background(:locals =&gt; { #{params.collect {|p| &quot;:#{p} =&gt; #{p}&quot; }.join(', ')} }) do
-              #{method}_without_background#{punctuation}(#{params.join(', ')})
-            end
-          end
-        }
-      end
+      # this is for backwards compatibility
+      background_method *args
     else
       options = args.first || {}
       locals = options.delete(:locals) || {}
       locals.each do |key, value|
-        locals[key] = value.dup rescue value
+        locals[key] = value.clone_for_background rescue value
       end
-      locals[:self] = self.dup
-      if options[:config]
-        #puts options[:config]
-        config = (Background::Config.load(options[:config].to_s) || {})
+      locals[:self] = self.clone_for_background
+      
+      config = (Background::Config.load(options[:config].to_s) || {})
+      handler = if Background.disabled
+        [:in_process]
       else
-        config = {}
+        [options.delete(:handler) || config[:handler] || Background::Config.default_handler].flatten
       end
-      #puts config.inspect
-      handler = [options.delete(:handler) || config[:handler] || Background::Config.default_handler].flatten
       reporter = options.delete(:reporter) || config[:reporter] || Background::Config.default_error_reporter
       
       handler.each do |hand|
@@ -170,7 +153,10 @@ module Kernel
         end
         
         begin
-          &quot;Background::#{hand.to_s.camelize}Handler&quot;.constantize.handle(locals, options, &amp;block)
+          Background.disable do
+            &quot;Background::#{hand.to_s.camelize}Handler&quot;.constantize.handle(locals, options, &amp;block)
+          end
+          
           return hand
         rescue Exception =&gt; e
           &quot;Background::#{reporter.to_s.camelize}ErrorReporter&quot;.constantize.report(e)
@@ -179,4 +165,8 @@ module Kernel
     end
     nil
   end
+  
+  def clone_for_background
+    dup
+  end
 end</diff>
      <filename>lib/core_ext/background.rb</filename>
    </modified>
    <modified>
      <diff>@@ -46,12 +46,17 @@ module Background #:nodoc:
     # Executes a marshalled message which was previously sent over ActiveMQ, in the context of the self
     # object, with all the other local variables defined.
     def self.execute(message)
-      code, obj, variables = self.decode(message)
-      puts &quot;--- executing code: #{code.source}\n--- with variables: #{variables.inspect}\n--- in object: #{obj.inspect}&quot;
+      begin
+        code, obj, variables = self.decode(message)
+        puts &quot;--- executing code: #{code.source}\n--- with variables: #{variables.inspect}\n--- in object: #{obj.inspect}\n--- with instance variables\n #{obj.instance_variables.collect { |v| v + &quot; ==&gt; &quot; + obj.instance_variable_get(v).inspect }.join(&quot;\n&quot;)}&quot;
 
-      obj.send :instance_eval, variables.collect { |key, value| &quot;#{key} = variables[:#{key}]&quot; }.join(';')
-      obj.send :instance_eval, code.source
-      puts &quot;--- it happened!&quot;
+        obj.send :instance_eval, variables.collect { |key, value| &quot;#{key} = variables[:#{key}]&quot; }.join(';')
+        obj.send :instance_eval, code.source
+        puts &quot;--- it happened!&quot;
+      rescue Exception =&gt; e
+        puts e.message
+        puts e.backtrace
+      end
     end
   end
 end</diff>
      <filename>lib/core_ext/handlers/active_messaging_handler.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,4 @@
-require 'rubygems'
-require 'activesupport'
-require 'test/unit'
-require File.dirname(__FILE__) + '/../init'
+require File.expand_path(File.dirname(__FILE__) + '/abstract_unit')
 
 class SomeBackgroundClass
   def add_three(a, b, c)
@@ -22,6 +19,7 @@ class BackgroundTest &lt; Test::Unit::TestCase
   def teardown
     Background::TestHandler.reset
     Background::TestErrorReporter.last_error = nil
+    Background.enable!
   end
   
   def test_should_run_code_block_in_background
@@ -110,4 +108,51 @@ class BackgroundTest &lt; Test::Unit::TestCase
     assert_not_nil Background::TestHandler.options
     assert_equal 2, Background::TestHandler.options[:some_option]
   end
+  
+  def test_should_correctly_marshal_classes
+    assert_equal SomeBackgroundClass, Marshal.load(Marshal.dump(SomeBackgroundClass.clone_for_background))
+  end
+  
+  def test_should_correctly_marshal_singleton_objects
+    obj = Object.new
+    def obj.some_method
+    end
+    
+    assert Marshal.load(Marshal.dump(obj.clone_for_background))
+  end
+  
+  def test_should_disable_background
+    Background.enable!
+    Background.disable do
+      assert Background.disabled
+    end
+    assert !Background.disabled
+  end
+
+  def test_should_disable_background_if_already_disabled
+    Background.disable!
+    Background.disable do
+      assert Background.disabled
+    end
+    assert Background.disabled
+  end
+  
+  def test_should_reenable_background_when_exception_is_raised_in_block
+    begin
+      Background.disable do
+        raise 'grr'
+      end
+    rescue RuntimeError =&gt; e
+      assert_equal 'grr', e.message
+    end
+    
+    assert !Background.disabled
+  end
+  
+  def test_should_disable_background_while_executing_block
+    Background.enable!
+    background :handler =&gt; :in_process do
+      assert Background.disabled
+    end
+  end
 end</diff>
      <filename>test/background_test.rb</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>test/config/background.yml</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>0dfe353eecaa910818d8977c6d2ebdf41779fd07</id>
    </parent>
  </parents>
  <author>
    <name>Thomas Kadauke</name>
    <email>tkadauke@imedo.de</email>
  </author>
  <url>http://github.com/imedo/background/commit/9792d10045ee3c417cf313d852319d09564ebb7e</url>
  <id>9792d10045ee3c417cf313d852319d09564ebb7e</id>
  <committed-date>2009-03-07T11:54:32-08:00</committed-date>
  <authored-date>2009-03-07T11:54:32-08:00</authored-date>
  <message>fixes in configuration loading; fixes in marshalling of active record objects</message>
  <tree>3c62495be45451e87af5a2ba3a442dac8d992d56</tree>
  <committer>
    <name>Thomas Kadauke</name>
    <email>tkadauke@imedo.de</email>
  </committer>
</commit>
