mongoid-publishable 0.0.1 → 0.0.2
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.
@@ -15,17 +15,35 @@ module Mongoid
|
|
15
15
|
end
|
16
16
|
|
17
17
|
module ClassMethods
|
18
|
+
# setter for the callbacks
|
19
|
+
def after_publish_callbacks=(values)
|
20
|
+
@after_publish_callbacks = CallbackCollection.new(values)
|
21
|
+
end
|
22
|
+
|
18
23
|
# returns the list of callbacks
|
19
24
|
def after_publish_callbacks
|
20
25
|
@after_publish_callbacks ||= CallbackCollection.new
|
21
26
|
end
|
22
27
|
|
28
|
+
def add_after_publish_callback(callback)
|
29
|
+
after_publish_callbacks << callback
|
30
|
+
subclasses.each do |subclass|
|
31
|
+
subclass.add_after_publish_callback(callback)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
23
35
|
# adds a callback to the list
|
24
36
|
def after_publish(*args, &block)
|
25
37
|
Callback.new(*args, &block).tap do |callback|
|
26
|
-
|
38
|
+
add_after_publish_callback(callback)
|
27
39
|
end
|
28
40
|
end
|
41
|
+
|
42
|
+
# pass the callbacks down to the sub-class
|
43
|
+
def inherited(subclass)
|
44
|
+
subclass.after_publish_callbacks = after_publish_callbacks
|
45
|
+
super
|
46
|
+
end
|
29
47
|
end
|
30
48
|
|
31
49
|
module InstanceMethods
|
@@ -9,6 +9,12 @@ describe Mongoid::Publishable::Callbacks do
|
|
9
9
|
CallbackableObject
|
10
10
|
end
|
11
11
|
|
12
|
+
before(:each) do
|
13
|
+
[CallbackableObject, CallbackableSubobject].each do |klass|
|
14
|
+
klass.after_publish_callbacks.replace []
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
12
18
|
describe "::after_publish_callbacks" do
|
13
19
|
it "should return an object that responds to #process" do
|
14
20
|
expect(subject.after_publish_callbacks).to respond_to :process
|
@@ -17,7 +23,6 @@ describe Mongoid::Publishable::Callbacks do
|
|
17
23
|
|
18
24
|
describe "::after_publish" do
|
19
25
|
it "should increment the callbacks by 1" do
|
20
|
-
subject.after_publish_callbacks.replace []
|
21
26
|
expect(subject.after_publish_callbacks.size).to eq 0
|
22
27
|
subject.after_publish(:method_name)
|
23
28
|
expect(subject.after_publish_callbacks.size).to eq 1
|
@@ -34,11 +39,35 @@ describe Mongoid::Publishable::Callbacks do
|
|
34
39
|
callback = subject.after_publish(:method_name)
|
35
40
|
expect(callback).to respond_to :process
|
36
41
|
end
|
42
|
+
|
43
|
+
it "should be inherited by any sub-classes" do
|
44
|
+
expect(CallbackableSubobject.after_publish_callbacks.size).to eq 0
|
45
|
+
CallbackableObject.after_publish(:method_name)
|
46
|
+
expect(CallbackableSubobject.after_publish_callbacks.size).to eq 1
|
47
|
+
end
|
37
48
|
end
|
38
49
|
|
39
50
|
end # class
|
40
51
|
|
41
|
-
context "
|
52
|
+
context "a sub-class of a class that's included Mongoid::Publishable::Callbacks" do
|
53
|
+
|
54
|
+
before(:each) do
|
55
|
+
[CallbackableObject, CallbackableSubobject].each do |klass|
|
56
|
+
klass.after_publish_callbacks.replace []
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "defining a callback" do
|
61
|
+
it "should not be defined on the parent class" do
|
62
|
+
expect(CallbackableObject.after_publish_callbacks.size).to eq 0
|
63
|
+
CallbackableSubobject.after_publish(:method_name)
|
64
|
+
expect(CallbackableObject.after_publish_callbacks.size).to eq 0
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
context "an instance of a class that's included Mongoid::Publishable::Callbacks" do
|
42
71
|
|
43
72
|
subject do
|
44
73
|
CallbackableObject.new
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-publishable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -129,6 +129,7 @@ files:
|
|
129
129
|
- spec/spec_helper.rb
|
130
130
|
- spec/support/env.rb
|
131
131
|
- spec/support/models/callbackable_object.rb
|
132
|
+
- spec/support/models/callbackable_subobject.rb
|
132
133
|
- spec/support/models/publishable_object.rb
|
133
134
|
- spec/support/models/publisher.rb
|
134
135
|
- spec/support/models/queuing_controller.rb
|
@@ -168,6 +169,7 @@ test_files:
|
|
168
169
|
- spec/spec_helper.rb
|
169
170
|
- spec/support/env.rb
|
170
171
|
- spec/support/models/callbackable_object.rb
|
172
|
+
- spec/support/models/callbackable_subobject.rb
|
171
173
|
- spec/support/models/publishable_object.rb
|
172
174
|
- spec/support/models/publisher.rb
|
173
175
|
- spec/support/models/queuing_controller.rb
|