backgrounded 2.0.0.pre2 → 2.0.0.rc1

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.rdoc CHANGED
@@ -8,8 +8,9 @@ Backgrounded provides a thin wrapper around any background processing framework
8
8
  * clean and concise API which removes any dependency on external "worker" jobs and allows you to execute any model method in the background
9
9
  * integrates with any background processing framework (DelayedJob, Resque, JobFu, Workling, etc)
10
10
  * background methods can be actually unit tested by using an 'in process' runner
11
+ * custom callbacks to execute ActiveRecord callbacks in the background after being committed to the database
11
12
 
12
- = Usage
13
+ = General Usage
13
14
 
14
15
  class User
15
16
  def do_stuff
@@ -25,6 +26,20 @@ Backgrounded provides a thin wrapper around any background processing framework
25
26
  # execute class method in background
26
27
  User.backgrounded.do_something_else
27
28
 
29
+ = after_commit_backgrounded Callback
30
+
31
+ Automatically execute a callback in the background after a model has been saved to the database. All of the standard after_commit options are
32
+ available as well as an optional :backgrounded option which will be passed to the Backgrounded::Handler.
33
+
34
+ class User < ActiveRecord::Base
35
+ # execute :do_something in the background after committed
36
+ after_commit_backgrounded :do_something
37
+
38
+ # execute :do_something_else in the background after committed
39
+ # passing custom options to the backgrounded handler
40
+ after_commit_backgrounded :do_something_else, :backgrounded => {:priority => :high}
41
+ end
42
+
28
43
  = Installation
29
44
 
30
45
  Bundler Gemfile configuration
data/lib/backgrounded.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  require 'active_support/all'
2
2
 
3
3
  require File.join(File.dirname(__FILE__), 'backgrounded', 'handler', 'inprocess_handler')
4
- require File.join(File.dirname(__FILE__), 'backgrounded', 'proxy')
5
4
  require File.join(File.dirname(__FILE__), 'backgrounded', 'concern')
6
5
  require File.join(File.dirname(__FILE__), 'backgrounded', 'active_record_extension')
7
6
 
@@ -1,3 +1,5 @@
1
+ require File.join(File.dirname(__FILE__), 'proxy')
2
+
1
3
  module Backgrounded
2
4
  module Concern
3
5
  extend ActiveSupport::Concern
@@ -5,13 +7,15 @@ module Backgrounded
5
7
  module ClassMethods
6
8
  # @see Backgrounded::Concern#backgrounded
7
9
  def backgrounded(options={})
8
- Backgrounded::Proxy.new self, options
10
+ Backgrounded.handler.options = options
11
+ Backgrounded::Proxy.new self
9
12
  end
10
13
  end
11
14
 
12
15
  # @param options (optional) options to pass into the backgrounded handler
13
16
  def backgrounded(options={})
14
- Backgrounded::Proxy.new self, options
17
+ Backgrounded.handler.options = options
18
+ Backgrounded::Proxy.new self
15
19
  end
16
20
  end
17
21
  end
@@ -0,0 +1,11 @@
1
+ module Backgrounded
2
+ module Handler
3
+ class AbstractHandler
4
+ attr_accessor :options
5
+
6
+ def options
7
+ self.options || {}
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,8 +1,10 @@
1
+ require 'backgrounded/handler/abstract_handler'
2
+
1
3
  module Backgrounded
2
4
  module Handler
3
5
  #simple handler to process synchronously and not actually in the background
4
6
  #useful for testing
5
- class InprocessHandler
7
+ class InprocessHandler < AbstractHandler
6
8
  def request(object, method, args, options={})
7
9
  object.send method, *args
8
10
  end
@@ -1,9 +1,11 @@
1
+ require 'backgrounded/handler/abstract_handler'
2
+
1
3
  module Backgrounded
2
4
  module Handler
3
5
  # throw requests out the window
4
6
  # useful for test environment to avoid any background work
5
- class NoOpHandler
6
- def request(object, method, args, options={})
7
+ class NoOpHandler < AbstractHandler
8
+ def request(object, method, args)
7
9
  # do nothing
8
10
  end
9
11
  end
@@ -1,13 +1,12 @@
1
1
  module Backgrounded
2
2
  class Proxy
3
- def initialize(delegate, options={})
3
+ def initialize(delegate)
4
4
  @delegate = delegate
5
- @options = options
6
5
  end
7
6
 
8
7
  def method_missing(method_name, *args)
9
8
  Backgrounded.logger.debug("Requesting #{Backgrounded.handler} backgrounded method: #{method_name} for instance #{@delegate}")
10
- Backgrounded.handler.request(@delegate, method_name, args, @options)
9
+ Backgrounded.handler.request(@delegate, method_name, args)
11
10
  nil
12
11
  end
13
12
  end
@@ -1,3 +1,3 @@
1
1
  module Backgrounded
2
- VERSION = "2.0.0.pre2"
2
+ VERSION = "2.0.0.rc1"
3
3
  end
@@ -27,11 +27,11 @@ class ActiveRecordExtensionTest < Test::Unit::TestCase
27
27
  end
28
28
  context 'when callback has :backgrounded options' do
29
29
  setup do
30
- Backgrounded.handler.expects(:request).with(anything, anything, anything, {:priority => :high})
30
+ Backgrounded.handler.expects(:options=).with(:priority => :high)
31
31
  @user = User.new
32
32
  @user.save
33
33
  end
34
- should 'pass options onto the Backgrounded::Handler#request method' do end # see expectations
34
+ should 'pass configure Backgrounded.handler.options' do end # see expectations
35
35
  end
36
36
  end
37
37
  end
@@ -35,11 +35,10 @@ class BackgroundedTest < Test::Unit::TestCase
35
35
  end
36
36
  context 'invoking with options' do
37
37
  setup do
38
+ Backgrounded.handler.expects(:options=).with(:priority => :high)
38
39
  @result = User.backgrounded(:priority => :high)
39
40
  end
40
- should 'initialize proxy with options' do
41
- assert_equal({:priority => :high}, @result.instance_variable_get(:@options))
42
- end
41
+ should 'pass options onto Backgrounded.handler' do end # see expectations
43
42
  end
44
43
  end
45
44
  end
data/test/proxy_test.rb CHANGED
@@ -36,14 +36,5 @@ class ProxyTest < Test::Unit::TestCase
36
36
  end
37
37
  should "execute method on delegate" do end #see expectations
38
38
  end
39
- context 'context when proxy is configured with options' do
40
- setup do
41
- Backgrounded.handler.expects(:request).with(anything, anything, anything, {:priority => :high})
42
- @delegate = User
43
- @proxy = Backgrounded::Proxy.new @delegate, :priority => :high
44
- @proxy.do_something_else
45
- end
46
- should 'pass options onto Backgrounded.handler' do end # see expectations
47
- end
48
39
  end
49
40
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backgrounded
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre2
4
+ version: 2.0.0.rc1
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-22 00:00:00.000000000 Z
12
+ date: 2012-05-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &2175352840 !ruby/object:Gem::Requirement
16
+ requirement: &2174074900 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.3.10
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2175352840
24
+ version_requirements: *2174074900
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activesupport
27
- requirement: &2175352300 !ruby/object:Gem::Requirement
27
+ requirement: &2174074380 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 2.3.10
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2175352300
35
+ version_requirements: *2174074380
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: shoulda
38
- requirement: &2175351820 !ruby/object:Gem::Requirement
38
+ requirement: &2174073900 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2175351820
46
+ version_requirements: *2174073900
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: mocha
49
- requirement: &2175351340 !ruby/object:Gem::Requirement
49
+ requirement: &2174073420 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2175351340
57
+ version_requirements: *2174073420
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: sqlite3-ruby
60
- requirement: &2175350860 !ruby/object:Gem::Requirement
60
+ requirement: &2174072940 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.3.2
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2175350860
68
+ version_requirements: *2174072940
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
- requirement: &2175350380 !ruby/object:Gem::Requirement
71
+ requirement: &2174072460 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: 0.9.2.2
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2175350380
79
+ version_requirements: *2174072460
80
80
  description: Execute any ActiveRecord Model method in the background
81
81
  email:
82
82
  - ryan@codecrate.com
@@ -94,6 +94,7 @@ files:
94
94
  - lib/backgrounded.rb
95
95
  - lib/backgrounded/active_record_extension.rb
96
96
  - lib/backgrounded/concern.rb
97
+ - lib/backgrounded/handler/abstract_handler.rb
97
98
  - lib/backgrounded/handler/inprocess_handler.rb
98
99
  - lib/backgrounded/handler/no_op_handler.rb
99
100
  - lib/backgrounded/proxy.rb
@@ -117,7 +118,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
117
118
  version: '0'
118
119
  segments:
119
120
  - 0
120
- hash: 2468636028347354976
121
+ hash: 1327129114002778537
121
122
  required_rubygems_version: !ruby/object:Gem::Requirement
122
123
  none: false
123
124
  requirements: