sub_pub 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/Gemfile.lock +9 -1
- data/README.md +6 -0
- data/lib/sub_pub/active_record_subscriber.rb +12 -2
- data/lib/sub_pub/subscriber.rb +4 -0
- data/lib/sub_pub/version.rb +1 -1
- data/lib/sub_pub_matchers.rb +45 -0
- data/pkg/sub_pub-0.0.6.gem +0 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/unit/active_record_subscriber_spec.rb +37 -0
- data/spec/unit/subscriber_spec.rb +7 -45
- metadata +12 -3
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
sub_pub (0.0.
|
4
|
+
sub_pub (0.0.7)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -35,6 +35,7 @@ GEM
|
|
35
35
|
multi_json (~> 1.0)
|
36
36
|
arel (3.0.2)
|
37
37
|
builder (3.0.4)
|
38
|
+
coderay (1.0.8)
|
38
39
|
diff-lcs (1.1.3)
|
39
40
|
erubis (2.7.0)
|
40
41
|
hike (1.2.1)
|
@@ -45,10 +46,15 @@ GEM
|
|
45
46
|
i18n (>= 0.4.0)
|
46
47
|
mime-types (~> 1.16)
|
47
48
|
treetop (~> 1.4.8)
|
49
|
+
method_source (0.8.1)
|
48
50
|
mime-types (1.19)
|
49
51
|
multi_json (1.5.0)
|
50
52
|
pivotal_git_scripts (1.1.4)
|
51
53
|
polyglot (0.3.3)
|
54
|
+
pry (0.9.10)
|
55
|
+
coderay (~> 1.0.5)
|
56
|
+
method_source (~> 0.8)
|
57
|
+
slop (~> 3.3.1)
|
52
58
|
rack (1.4.1)
|
53
59
|
rack-cache (1.2)
|
54
60
|
rack (>= 0.4)
|
@@ -82,6 +88,7 @@ GEM
|
|
82
88
|
rspec-expectations (2.12.0)
|
83
89
|
diff-lcs (~> 1.1.3)
|
84
90
|
rspec-mocks (2.12.0)
|
91
|
+
slop (3.3.3)
|
85
92
|
sprockets (2.2.2)
|
86
93
|
hike (~> 1.2)
|
87
94
|
multi_json (~> 1.0)
|
@@ -104,6 +111,7 @@ PLATFORMS
|
|
104
111
|
DEPENDENCIES
|
105
112
|
activerecord
|
106
113
|
pivotal_git_scripts
|
114
|
+
pry
|
107
115
|
rails
|
108
116
|
rspec
|
109
117
|
sqlite3
|
data/README.md
CHANGED
@@ -1,8 +1,18 @@
|
|
1
1
|
module SubPub
|
2
2
|
module ActiveRecord
|
3
3
|
class Subscriber < SubPub::Subscriber
|
4
|
-
def self.subscribe_to(class_instance,
|
5
|
-
|
4
|
+
def self.subscribe_to(class_instance, callback_name)
|
5
|
+
@class_instance = class_instance
|
6
|
+
@callback_name = callback_name
|
7
|
+
super("active_record::#{@class_instance.to_s.underscore}::#{@callback_name}")
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.model_name
|
11
|
+
@class_instance.to_s
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.callback_name
|
15
|
+
@callback_name
|
6
16
|
end
|
7
17
|
|
8
18
|
def record
|
data/lib/sub_pub/subscriber.rb
CHANGED
data/lib/sub_pub/version.rb
CHANGED
@@ -0,0 +1,45 @@
|
|
1
|
+
module SubPub
|
2
|
+
module Matchers
|
3
|
+
def subscribe_to_model(expected)
|
4
|
+
SubscribeToModel.new(expected)
|
5
|
+
end
|
6
|
+
|
7
|
+
def subscribe_to_callback(expected)
|
8
|
+
SubscribeToModelCallback.new(expected)
|
9
|
+
end
|
10
|
+
|
11
|
+
def subscribe_to_topic(expected)
|
12
|
+
SubscribeToTopic.new(expected)
|
13
|
+
end
|
14
|
+
|
15
|
+
class SubscribeToTopic
|
16
|
+
def initialize(expected_topic)
|
17
|
+
@expected_topic = expected_topic
|
18
|
+
end
|
19
|
+
|
20
|
+
def matches?(subject)
|
21
|
+
subject.topic_name.should == @expected_topic
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class SubscribeToModel
|
26
|
+
def initialize(expected)
|
27
|
+
@expected = expected
|
28
|
+
end
|
29
|
+
|
30
|
+
def matches?(subject)
|
31
|
+
@expected.name.should == subject.model_name
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class SubscribeToModelCallback
|
36
|
+
def initialize(expected)
|
37
|
+
@expected = expected
|
38
|
+
end
|
39
|
+
|
40
|
+
def matches?(subject)
|
41
|
+
@expected.should == subject.callback_name
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
Binary file
|
data/spec/spec_helper.rb
CHANGED
@@ -19,6 +19,8 @@ RSpec.configure do |config|
|
|
19
19
|
# Load the environment
|
20
20
|
#
|
21
21
|
require 'bundler'
|
22
|
+
require 'sub_pub_matchers'
|
23
|
+
|
22
24
|
Bundler.require
|
23
25
|
|
24
26
|
#
|
@@ -40,6 +42,7 @@ RSpec.configure do |config|
|
|
40
42
|
# Use with_model
|
41
43
|
#
|
42
44
|
config.extend WithModel
|
45
|
+
config.include SubPub::Matchers
|
43
46
|
|
44
47
|
#
|
45
48
|
# Ensure pubsub is enabled
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SubPub::ActiveRecord::Subscriber do
|
4
|
+
with_model :FooBar do
|
5
|
+
table do |t|
|
6
|
+
t.string :title
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
before do
|
11
|
+
class Fooz < SubPub::ActiveRecord::Subscriber
|
12
|
+
subscribe_to(FooBar, 'after_create')
|
13
|
+
end
|
14
|
+
|
15
|
+
class Bazz < SubPub::ActiveRecord::Subscriber
|
16
|
+
subscribe_to(FooBar, 'after_create')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns the model name observed" do
|
21
|
+
Fooz.model_name.should == 'FooBar'
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns the callback observed" do
|
25
|
+
Bazz.callback_name.should == 'after_create'
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'matchers' do
|
29
|
+
subject do
|
30
|
+
Fooz
|
31
|
+
end
|
32
|
+
|
33
|
+
it { should subscribe_to_model(FooBar) }
|
34
|
+
it { should subscribe_to_callback("after_create") }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
@@ -1,55 +1,17 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe SubPub::Subscriber do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
describe ".topic" do
|
8
|
-
it "sets up a subscription" do
|
9
|
-
FooBar.class_eval do
|
10
|
-
subscribe_to("foo")
|
11
|
-
end
|
12
|
-
|
13
|
-
FooBar.topic.should == 'foo'
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe ".subscription" do
|
18
|
-
it "should be the result of the subscribe" do
|
19
|
-
subscription = stub
|
20
|
-
|
21
|
-
SubPub.should_receive(:subscribe).with('topic-name') { subscription }
|
22
|
-
|
23
|
-
FooBar.class_eval do
|
24
|
-
subscribe_to("topic-name")
|
25
|
-
end
|
26
|
-
|
27
|
-
FooBar.subscription.should be(subscription)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe ".publish" do
|
32
|
-
it "notifies the subscription of the publish event" do
|
33
|
-
subscription = double
|
34
|
-
subscription.should_receive(:on_publish)
|
35
|
-
FooBar.publish(subscription)
|
4
|
+
before do
|
5
|
+
class Bazero < SubPub::Subscriber
|
6
|
+
subscribe_to('foo_bar_topic')
|
36
7
|
end
|
37
8
|
end
|
38
9
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe "payload" do
|
46
|
-
let(:payload) { double }
|
47
|
-
it "has a payload" do
|
48
|
-
FooBar.new(payload).payload.should == payload
|
10
|
+
context "subscriber" do
|
11
|
+
subject do
|
12
|
+
Bazero
|
49
13
|
end
|
50
14
|
|
51
|
-
it
|
52
|
-
FooBar.new(payload).options.should == payload
|
53
|
-
end
|
15
|
+
it { should subscribe_to_topic('foo_bar_topic') }
|
54
16
|
end
|
55
17
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sub_pub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-21 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: In process publish/subscribe for Ruby
|
15
15
|
email:
|
@@ -35,10 +35,13 @@ files:
|
|
35
35
|
- lib/sub_pub/subscriber.rb
|
36
36
|
- lib/sub_pub/subscription.rb
|
37
37
|
- lib/sub_pub/version.rb
|
38
|
+
- lib/sub_pub_matchers.rb
|
38
39
|
- pkg/sub_pub-0.0.3.gem
|
39
40
|
- pkg/sub_pub-0.0.4.gem
|
41
|
+
- pkg/sub_pub-0.0.6.gem
|
40
42
|
- spec/integration/sub_pub_spec.rb
|
41
43
|
- spec/spec_helper.rb
|
44
|
+
- spec/unit/active_record_subscriber_spec.rb
|
42
45
|
- spec/unit/register_spec.rb
|
43
46
|
- spec/unit/subscriber_spec.rb
|
44
47
|
- sub_pub.gemspec
|
@@ -54,12 +57,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
54
57
|
- - ! '>='
|
55
58
|
- !ruby/object:Gem::Version
|
56
59
|
version: '0'
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
hash: 246920761593909108
|
57
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
64
|
none: false
|
59
65
|
requirements:
|
60
66
|
- - ! '>='
|
61
67
|
- !ruby/object:Gem::Version
|
62
68
|
version: '0'
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
hash: 246920761593909108
|
63
72
|
requirements: []
|
64
73
|
rubyforge_project:
|
65
74
|
rubygems_version: 1.8.24
|
@@ -70,6 +79,6 @@ summary: SubPub is a thin wrapper around ActiveSupport::Notifications, which pro
|
|
70
79
|
test_files:
|
71
80
|
- spec/integration/sub_pub_spec.rb
|
72
81
|
- spec/spec_helper.rb
|
82
|
+
- spec/unit/active_record_subscriber_spec.rb
|
73
83
|
- spec/unit/register_spec.rb
|
74
84
|
- spec/unit/subscriber_spec.rb
|
75
|
-
has_rdoc:
|