bustle 0.1.0 → 0.1.1
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.md +20 -5
- data/lib/bustle/activities.rb +10 -4
- data/lib/bustle/models/publisher.rb +2 -2
- data/lib/bustle/version.rb +1 -1
- data/specs/bustle/activities_spec.rb +9 -4
- data/specs/bustle/models/publisher_spec.rb +4 -1
- data/specs/support/active_record_tables.rb +2 -1
- data/specs/support/shared_examples/has_activities.rb +1 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -12,9 +12,11 @@ The advantages of Bustle are:
|
|
12
12
|
- It is lightweight and simple to use
|
13
13
|
- It is largely self-contained and separated from you core app logic
|
14
14
|
- It works nicely with ActiveRecord out of box
|
15
|
-
- It can be extended to use with other databases
|
15
|
+
- It is ORM-agnostic therefore can be extended to use with other databases
|
16
16
|
- It has full unit test coverage
|
17
17
|
|
18
|
+
Bustle is built for simplicity and extensibility. If you are after high performance pub/sub then this gem is not for you.
|
19
|
+
|
18
20
|
## Installation
|
19
21
|
|
20
22
|
Add this line to your application's Gemfile:
|
@@ -45,7 +47,8 @@ class CreateBustleTables < ActiveRecord::Migration
|
|
45
47
|
create_table :bustle_activities do |t|
|
46
48
|
t.string :resource_class
|
47
49
|
t.integer :resource_id
|
48
|
-
t.string :action
|
50
|
+
t.string :action, :default => ''
|
51
|
+
t.text :data, :default => ''
|
49
52
|
t.integer :publisher_id, :null => false
|
50
53
|
t.timestamps
|
51
54
|
end
|
@@ -153,16 +156,28 @@ Bustle::Subscriptions.get(bustle_publisher, bustle_subscriber).destroy
|
|
153
156
|
#### Publish an Activity
|
154
157
|
|
155
158
|
```ruby
|
156
|
-
Bustle::Activities.add bustle_publisher,
|
159
|
+
Bustle::Activities.add bustle_publisher, {
|
160
|
+
:resource => some_resource,
|
161
|
+
:action => some_string,
|
162
|
+
:data => some_text
|
163
|
+
}
|
157
164
|
# or
|
158
|
-
Bustle::Publisher.publish
|
165
|
+
Bustle::Publisher.publish({
|
166
|
+
:resource => some_resource,
|
167
|
+
:action => some_string,
|
168
|
+
:data => some_text
|
169
|
+
})
|
159
170
|
|
160
171
|
# example
|
161
172
|
post = Post.find(1)
|
162
173
|
comment = post.comments.add(:content => "I'm a comment")
|
163
174
|
Bustle::Publishers.add post
|
164
175
|
publisher = Bustle::Publishers.get post
|
165
|
-
publisher.publish
|
176
|
+
publisher.publish({
|
177
|
+
:resource => comment,
|
178
|
+
:action => 'new,
|
179
|
+
:data => 'a new comment has been posted'
|
180
|
+
})
|
166
181
|
```
|
167
182
|
|
168
183
|
#### Activities
|
data/lib/bustle/activities.rb
CHANGED
@@ -6,11 +6,17 @@ module Bustle
|
|
6
6
|
include Concern::ByPublisher
|
7
7
|
|
8
8
|
class << self
|
9
|
-
def add(publisher,
|
9
|
+
def add(publisher, data = {})
|
10
|
+
if resource = data.delete(:resource)
|
11
|
+
data[:resource_class] = resource.class.name
|
12
|
+
data[:resource_id] = resource.id
|
13
|
+
end
|
14
|
+
|
10
15
|
Activity.to_adapter.create!(
|
11
|
-
:resource_class =>
|
12
|
-
:resource_id =>
|
13
|
-
:action => action,
|
16
|
+
:resource_class => data[:resource_class],
|
17
|
+
:resource_id => data[:resource_id],
|
18
|
+
:action => data[:action],
|
19
|
+
:data => data[:data],
|
14
20
|
:publisher_id => publisher.id
|
15
21
|
)
|
16
22
|
end
|
data/lib/bustle/version.rb
CHANGED
@@ -10,20 +10,25 @@ module Bustle
|
|
10
10
|
let(:subscriber2) { Subscribers.add user }
|
11
11
|
|
12
12
|
it "creates an activity" do
|
13
|
-
Activities.add publisher,
|
13
|
+
Activities.add publisher, {
|
14
|
+
:action => 'show',
|
15
|
+
:resource => comment,
|
16
|
+
:data => 'hello world'
|
17
|
+
}
|
14
18
|
|
15
19
|
activity = Activity.to_adapter.get(1)
|
16
20
|
activity.resource_class.should == 'Bustle::Dummy::Comment'
|
17
21
|
activity.resource_id.should == 101
|
18
22
|
activity.action.should == 'show'
|
23
|
+
activity.data.should == 'hello world'
|
19
24
|
activity.publisher_id.should == publisher.id
|
20
25
|
end
|
21
26
|
|
22
27
|
context "multiple activities" do
|
23
28
|
before do
|
24
|
-
2.times { Activities.add publisher, 'show'
|
25
|
-
1.times { Activities.add publisher, 'reply'
|
26
|
-
2.times { Activities.add publisher2, 'reply'
|
29
|
+
2.times { Activities.add publisher, { :action => 'show' } }
|
30
|
+
1.times { Activities.add publisher, { :action => 'reply' } }
|
31
|
+
2.times { Activities.add publisher2, { :action => 'reply' } }
|
27
32
|
end
|
28
33
|
|
29
34
|
it "finds all activities" do
|
@@ -10,7 +10,10 @@ module Bustle
|
|
10
10
|
|
11
11
|
it "is able to publish an activity" do
|
12
12
|
publisher = Publishers.add post
|
13
|
-
publisher.publish
|
13
|
+
publisher.publish({
|
14
|
+
:resource => comment,
|
15
|
+
:action => 'reply'
|
16
|
+
})
|
14
17
|
Activity.to_adapter.get(1).action.should == 'reply'
|
15
18
|
end
|
16
19
|
end
|
@@ -19,7 +19,8 @@ ActiveRecord::Migration.suppress_messages do
|
|
19
19
|
create_table :bustle_activities, :force => true do |t|
|
20
20
|
t.string :resource_class
|
21
21
|
t.integer :resource_id
|
22
|
-
t.string :action
|
22
|
+
t.string :action, :default => ''
|
23
|
+
t.text :data, :default => ''
|
23
24
|
t.integer :publisher_id
|
24
25
|
t.timestamps
|
25
26
|
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.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -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: -534014299533993721
|
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: -534014299533993721
|
247
247
|
requirements: []
|
248
248
|
rubyforge_project:
|
249
249
|
rubygems_version: 1.8.24
|