bustle 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
data/README.md
CHANGED
@@ -99,7 +99,10 @@ When activities occur:
|
|
99
99
|
#### Register a Subscriber
|
100
100
|
|
101
101
|
```ruby
|
102
|
+
# returns a subscriber instance upon duplicated entry
|
102
103
|
Bustle::Subscribers.add subscriber
|
104
|
+
# raises error upon duplicated entry
|
105
|
+
Bustle::Subscribers.add! subscriber
|
103
106
|
|
104
107
|
# example
|
105
108
|
user = User.find(1)
|
@@ -109,7 +112,10 @@ Bustle::Subscribers.add user
|
|
109
112
|
#### Register a Publisher
|
110
113
|
|
111
114
|
```ruby
|
115
|
+
# returns a publisher instance upon duplicated entry
|
112
116
|
Bustle::Publishers.add publisher
|
117
|
+
# raises error upon duplicated entry
|
118
|
+
Bustle::Publishers.add! publisher
|
113
119
|
|
114
120
|
# example
|
115
121
|
post = Post.find(1)
|
@@ -175,8 +181,8 @@ Bustle::Publishers.add post
|
|
175
181
|
publisher = Bustle::Publishers.get post
|
176
182
|
publisher.publish({
|
177
183
|
:resource => comment,
|
178
|
-
:action => 'new,
|
179
|
-
:data => '
|
184
|
+
:action => 'new',
|
185
|
+
:data => 'useful for putting serialized data or JSON here'
|
180
186
|
})
|
181
187
|
```
|
182
188
|
|
@@ -4,6 +4,12 @@ module Bustle::Concern
|
|
4
4
|
|
5
5
|
module ClassMethods
|
6
6
|
def add(resource)
|
7
|
+
add!(resource)
|
8
|
+
rescue
|
9
|
+
get(resource)
|
10
|
+
end
|
11
|
+
|
12
|
+
def add!(resource)
|
7
13
|
self::RESOURCE_NAME.constantize.to_adapter.create!(
|
8
14
|
:resource_class => resource.class.name,
|
9
15
|
:resource_id => resource.id
|
data/lib/bustle/version.rb
CHANGED
@@ -42,5 +42,12 @@ ActiveRecord::Migration.suppress_messages do
|
|
42
42
|
t.integer :subscriber_id
|
43
43
|
t.timestamps
|
44
44
|
end
|
45
|
+
|
46
|
+
add_index :bustle_activities, :publisher_id
|
47
|
+
add_index :bustle_publishers, [:resource_class, :resource_id], :unique => true
|
48
|
+
add_index :bustle_subscribers, [:resource_class, :resource_id], :unique => true
|
49
|
+
add_index :bustle_subscriptions, :publisher_id
|
50
|
+
add_index :bustle_subscriptions, :subscriber_id
|
51
|
+
add_index :bustle_subscriptions, [:publisher_id, :subscriber_id], :unique => true
|
45
52
|
end
|
46
53
|
end
|
@@ -1,24 +1,46 @@
|
|
1
1
|
shared_examples 'resource_collection' do
|
2
2
|
let(:resource_class) { described_class::RESOURCE_NAME.constantize.to_adapter }
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
context "#add" do
|
5
|
+
it "adds a model record" do
|
6
|
+
described_class.add(user).resource_class.should == 'Bustle::Dummy::User'
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
it "gets the model if it already exists" do
|
10
|
+
described_class.add(user)
|
11
|
+
described_class.add(user).resource_class.should == 'Bustle::Dummy::User'
|
12
|
+
end
|
13
|
+
|
14
|
+
it "explicitly adds a model record" do
|
15
|
+
described_class.add!(user).resource_class.should == 'Bustle::Dummy::User'
|
16
|
+
end
|
13
17
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
+
it "raises error if the model already exists" do
|
19
|
+
described_class.add(user)
|
20
|
+
expect { described_class.add!(user) }.to raise_error
|
21
|
+
end
|
18
22
|
end
|
19
23
|
|
20
|
-
|
21
|
-
|
22
|
-
|
24
|
+
context "get/remove" do
|
25
|
+
before do
|
26
|
+
described_class.add user
|
27
|
+
end
|
28
|
+
|
29
|
+
it "adds a model record" do
|
30
|
+
model = resource_class.get(1)
|
31
|
+
model.resource_class.should == 'Bustle::Dummy::User'
|
32
|
+
model.resource_id.should == 42
|
33
|
+
end
|
34
|
+
|
35
|
+
it "finds a model record" do
|
36
|
+
model = described_class.get user
|
37
|
+
model.resource_class.should == 'Bustle::Dummy::User'
|
38
|
+
model.resource_id.should == 42
|
39
|
+
end
|
40
|
+
|
41
|
+
it "removes a model record" do
|
42
|
+
described_class.remove(user)
|
43
|
+
resource_class.find_all({}).count.should == 0
|
44
|
+
end
|
23
45
|
end
|
24
46
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bustle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
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-06-
|
12
|
+
date: 2012-06-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -234,7 +234,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
234
234
|
version: '0'
|
235
235
|
segments:
|
236
236
|
- 0
|
237
|
-
hash:
|
237
|
+
hash: 1375749694743315937
|
238
238
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
239
239
|
none: false
|
240
240
|
requirements:
|
@@ -243,7 +243,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
243
243
|
version: '0'
|
244
244
|
segments:
|
245
245
|
- 0
|
246
|
-
hash:
|
246
|
+
hash: 1375749694743315937
|
247
247
|
requirements: []
|
248
248
|
rubyforge_project:
|
249
249
|
rubygems_version: 1.8.24
|