stream_rails 2.0 → 2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +27 -13
- data/lib/stream_rails/activity.rb +5 -1
- data/lib/stream_rails/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e747d58bdea6d8fb3730c4c989473f80742aa27
|
4
|
+
data.tar.gz: 7de3ea1b730b2ab6776357285fee6e828ab870f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90acf4f1f8b17e3c8310f55b24bec008340b71772f8b831c8b8d740affc2503c826c6fc40d4f2c528d218591fe0344913c036f1666253c830d35a112e0bd5e88
|
7
|
+
data.tar.gz: aad3af59da1f2b7c27c9f19ae47dc7c66a80cd1072d8a8ae0c7f3d6a1210d2ca4dcd206ae762e3db2fe11395b225393795d522e9ad8db3842ceef8dea8c63fbf
|
data/README.md
CHANGED
@@ -74,26 +74,24 @@ class Pin < ActiveRecord::Base
|
|
74
74
|
|
75
75
|
include StreamRails::Activity
|
76
76
|
as_activity
|
77
|
+
|
78
|
+
def activity_object
|
79
|
+
self.item
|
80
|
+
end
|
81
|
+
|
77
82
|
end
|
78
83
|
```
|
79
84
|
Everytime a Pin is created it will be stored in the feed of the user that created it, and when a Pin instance is deleted than it will get removed as well.
|
80
85
|
|
81
86
|
####Activity fields
|
82
87
|
|
83
|
-
|
84
|
-
|
85
|
-
**object** is a reference to the model instance itself
|
86
|
-
**actor** is a reference to the user attribute of the instance
|
87
|
-
**verb** is a string representation of the class name
|
88
|
+
ActiveRecord models are stored in your feeds as activities; Activities are objects that tell the story of a person performing an action on or with an object, in its simplest form, an activity consists of an actor, a verb, and an object. In order for this to happen your models need to implement this methods:
|
88
89
|
|
89
|
-
|
90
|
+
**#activity_object** the object of the activity (eg. an AR model instance)
|
91
|
+
**#activity_actor** the actor performing the activity (defaults to ```self.user```)
|
92
|
+
**#activity_verb** the string representation of the verb (defaults to model class name)
|
90
93
|
|
91
|
-
|
92
|
-
2. the model table has timestamp columns (created_at is required)
|
93
|
-
|
94
|
-
You can change this behaviour by overriding ```#activity_actor```.
|
95
|
-
|
96
|
-
Below shows an example how to change your class if the model belongs to an author instead of to a user.
|
94
|
+
Here's a more complete example of the Pin class:
|
97
95
|
|
98
96
|
```ruby
|
99
97
|
class Pin < ActiveRecord::Base
|
@@ -107,6 +105,10 @@ class Pin < ActiveRecord::Base
|
|
107
105
|
self.author
|
108
106
|
end
|
109
107
|
|
108
|
+
def activity_object
|
109
|
+
self.item
|
110
|
+
end
|
111
|
+
|
110
112
|
end
|
111
113
|
```
|
112
114
|
|
@@ -127,6 +129,10 @@ class Pin < ActiveRecord::Base
|
|
127
129
|
{'is_retweet' => self.is_retweet}
|
128
130
|
end
|
129
131
|
|
132
|
+
def activity_object
|
133
|
+
self.item
|
134
|
+
end
|
135
|
+
|
130
136
|
end
|
131
137
|
```
|
132
138
|
|
@@ -184,6 +190,10 @@ class Pin < ActiveRecord::Base
|
|
184
190
|
end
|
185
191
|
end
|
186
192
|
|
193
|
+
def activity_object
|
194
|
+
self.item
|
195
|
+
end
|
196
|
+
|
187
197
|
end
|
188
198
|
```
|
189
199
|
|
@@ -204,6 +214,10 @@ class Follow < ActiveRecord::Base
|
|
204
214
|
[feed_manager.get_notification_feed(self.target_id)]
|
205
215
|
end
|
206
216
|
|
217
|
+
def activity_object
|
218
|
+
self.target
|
219
|
+
end
|
220
|
+
|
207
221
|
end
|
208
222
|
```
|
209
223
|
|
@@ -221,7 +235,7 @@ StreamRails.feed_manager.follow_user(user_id, target_id)
|
|
221
235
|
When you read data from feeds, a pin activity will look like this:
|
222
236
|
|
223
237
|
```json
|
224
|
-
{"actor": "User:1", "verb": "like", "object": "
|
238
|
+
{"actor": "User:1", "verb": "like", "object": "Item:42"}
|
225
239
|
```
|
226
240
|
|
227
241
|
This is far from ready for usage in your template. We call the process of loading the references from the database enrichment. An example is shown below:
|
@@ -52,12 +52,16 @@ module StreamRails
|
|
52
52
|
StreamRails.create_reference(self.activity_actor)
|
53
53
|
end
|
54
54
|
|
55
|
+
def activity_object
|
56
|
+
raise NotImplementedError, "Activity models must define `#activity_object`"
|
57
|
+
end
|
58
|
+
|
55
59
|
def activity_verb
|
56
60
|
self.class.model_name.to_s
|
57
61
|
end
|
58
62
|
|
59
63
|
def activity_object_id
|
60
|
-
StreamRails.create_reference(self)
|
64
|
+
StreamRails.create_reference(self.activity_object)
|
61
65
|
end
|
62
66
|
|
63
67
|
def activity_foreign_id
|
data/lib/stream_rails/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stream_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '2.
|
4
|
+
version: '2.1'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tommaso Barbugli
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|