backgrounded 2.0.0.pre1 → 2.0.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/backgrounded.rb +2 -16
- data/lib/backgrounded/active_record_extension.rb +18 -0
- data/lib/backgrounded/concern.rb +18 -0
- data/lib/backgrounded/version.rb +1 -1
- data/test/active_record_extension_test.rb +37 -0
- metadata +18 -14
data/lib/backgrounded.rb
CHANGED
@@ -2,29 +2,15 @@ require 'active_support/all'
|
|
2
2
|
|
3
3
|
require File.join(File.dirname(__FILE__), 'backgrounded', 'handler', 'inprocess_handler')
|
4
4
|
require File.join(File.dirname(__FILE__), 'backgrounded', 'proxy')
|
5
|
+
require File.join(File.dirname(__FILE__), 'backgrounded', 'concern')
|
6
|
+
require File.join(File.dirname(__FILE__), 'backgrounded', 'active_record_extension')
|
5
7
|
|
6
8
|
module Backgrounded
|
7
|
-
extend ActiveSupport::Concern
|
8
|
-
|
9
9
|
class << self
|
10
10
|
attr_accessor :logger, :handler
|
11
11
|
end
|
12
|
-
|
13
|
-
module ClassMethods
|
14
|
-
def backgrounded(options={})
|
15
|
-
Backgrounded::Proxy.new self, options
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
# @param options (optional) options to pass into the backgrounded handler
|
20
|
-
def backgrounded(options={})
|
21
|
-
Backgrounded::Proxy.new self, options
|
22
|
-
end
|
23
12
|
end
|
24
13
|
|
25
|
-
# include backgrounded into any ruby object
|
26
|
-
Object.send(:include, Backgrounded)
|
27
|
-
|
28
14
|
# default handler to the basic in process handler
|
29
15
|
Backgrounded.handler = Backgrounded::Handler::InprocessHandler.new
|
30
16
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'active_record/base'
|
2
|
+
|
3
|
+
module Backgrounded
|
4
|
+
module ActiveRecordExtension
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
# execute a method in the background after the object is committed to the database
|
9
|
+
# @option options [Hash] :backgrounded (optional) options to pass into the backgrounded handler
|
10
|
+
# @see after_commit
|
11
|
+
def after_commit_backgrounded(method_name, options={})
|
12
|
+
backgrounded_options = options.delete :backgrounded
|
13
|
+
after_commit Proc.new {|o| o.backgrounded(backgrounded_options).send(method_name) }, options
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
ActiveRecord::Base.send(:include, Backgrounded::ActiveRecordExtension)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Backgrounded
|
2
|
+
module Concern
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
# @see Backgrounded::Concern#backgrounded
|
7
|
+
def backgrounded(options={})
|
8
|
+
Backgrounded::Proxy.new self, options
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# @param options (optional) options to pass into the backgrounded handler
|
13
|
+
def backgrounded(options={})
|
14
|
+
Backgrounded::Proxy.new self, options
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
Object.send(:include, Backgrounded::Concern)
|
data/lib/backgrounded/version.rb
CHANGED
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
class ActiveRecordExtensionTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
class Blog < ActiveRecord::Base
|
6
|
+
after_commit_backgrounded :do_something_else
|
7
|
+
def do_something_else
|
8
|
+
end
|
9
|
+
end
|
10
|
+
class User < ActiveRecord::Base
|
11
|
+
after_commit_backgrounded :do_stuff, :backgrounded => {:priority => :high}
|
12
|
+
def do_stuff
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context '.after_commit_backgrounded' do
|
17
|
+
should 'be defined on ActiveRecord::Base' do
|
18
|
+
assert ActiveRecord::Base.respond_to?(:after_commit_backgrounded)
|
19
|
+
end
|
20
|
+
context 'when using default options' do
|
21
|
+
setup do
|
22
|
+
@blog = Blog.new
|
23
|
+
@blog.expects(:do_something_else)
|
24
|
+
@blog.save
|
25
|
+
end
|
26
|
+
should 'execute callbacks' do end # see expectations
|
27
|
+
end
|
28
|
+
context 'when callback has :backgrounded options' do
|
29
|
+
setup do
|
30
|
+
Backgrounded.handler.expects(:request).with(anything, anything, anything, {:priority => :high})
|
31
|
+
@user = User.new
|
32
|
+
@user.save
|
33
|
+
end
|
34
|
+
should 'pass options onto the Backgrounded::Handler#request method' do end # see expectations
|
35
|
+
end
|
36
|
+
end
|
37
|
+
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.
|
4
|
+
version: 2.0.0.pre2
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-05-22 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
16
|
-
requirement: &
|
16
|
+
requirement: &2175352840 !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: *
|
24
|
+
version_requirements: *2175352840
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: activesupport
|
27
|
-
requirement: &
|
27
|
+
requirement: &2175352300 !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: *
|
35
|
+
version_requirements: *2175352300
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: shoulda
|
38
|
-
requirement: &
|
38
|
+
requirement: &2175351820 !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: *
|
46
|
+
version_requirements: *2175351820
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: mocha
|
49
|
-
requirement: &
|
49
|
+
requirement: &2175351340 !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: *
|
57
|
+
version_requirements: *2175351340
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: sqlite3-ruby
|
60
|
-
requirement: &
|
60
|
+
requirement: &2175350860 !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: *
|
68
|
+
version_requirements: *2175350860
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake
|
71
|
-
requirement: &
|
71
|
+
requirement: &2175350380 !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: *
|
79
|
+
version_requirements: *2175350380
|
80
80
|
description: Execute any ActiveRecord Model method in the background
|
81
81
|
email:
|
82
82
|
- ryan@codecrate.com
|
@@ -92,10 +92,13 @@ files:
|
|
92
92
|
- Rakefile
|
93
93
|
- backgrounded.gemspec
|
94
94
|
- lib/backgrounded.rb
|
95
|
+
- lib/backgrounded/active_record_extension.rb
|
96
|
+
- lib/backgrounded/concern.rb
|
95
97
|
- lib/backgrounded/handler/inprocess_handler.rb
|
96
98
|
- lib/backgrounded/handler/no_op_handler.rb
|
97
99
|
- lib/backgrounded/proxy.rb
|
98
100
|
- lib/backgrounded/version.rb
|
101
|
+
- test/active_record_extension_test.rb
|
99
102
|
- test/backgrounded_test.rb
|
100
103
|
- test/database.yml
|
101
104
|
- test/proxy_test.rb
|
@@ -114,7 +117,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
114
117
|
version: '0'
|
115
118
|
segments:
|
116
119
|
- 0
|
117
|
-
hash:
|
120
|
+
hash: 2468636028347354976
|
118
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
122
|
none: false
|
120
123
|
requirements:
|
@@ -128,6 +131,7 @@ signing_key:
|
|
128
131
|
specification_version: 3
|
129
132
|
summary: Simple API to perform work in the background
|
130
133
|
test_files:
|
134
|
+
- test/active_record_extension_test.rb
|
131
135
|
- test/backgrounded_test.rb
|
132
136
|
- test/database.yml
|
133
137
|
- test/proxy_test.rb
|