stream_rails 2.3.1 → 2.4.0
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.
- checksums.yaml +4 -4
- data/README.md +94 -2
- data/lib/stream_rails.rb +9 -10
- data/lib/stream_rails/activity.rb +21 -26
- data/lib/stream_rails/config.rb +7 -8
- data/lib/stream_rails/enrich.rb +25 -32
- data/lib/stream_rails/feed_manager.rb +20 -21
- data/lib/stream_rails/railtie.rb +0 -2
- data/lib/stream_rails/renderable.rb +7 -9
- data/lib/stream_rails/sync_policies.rb +34 -19
- data/lib/stream_rails/utils/view_helpers.rb +4 -3
- data/lib/stream_rails/version.rb +2 -2
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82fcbb047a9fc18b2f808bf7a0c9d24edc6fef5b
|
4
|
+
data.tar.gz: 8741b89406b037ea2b6be3769e5663395661d185
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 675e198519664358583be4d42e5265a0b7d74c4b3e212ec1296e9d34bad68e7e2277a97fe51902d24a33031f9aa6965d9ed25b39f4e93c5e11c1a42c99e0b55b
|
7
|
+
data.tar.gz: 7b21994454b8f1c62e17f7a642738c9c725ef717f29776c97c5fbee17373b210ae94c9718d3b33f10bea0b6ddf30662ec87c06f516c40d634004a49551edb65f
|
data/README.md
CHANGED
@@ -31,10 +31,20 @@ You can check out our example app built using this library on Github [https://gi
|
|
31
31
|
- [Table of Contents](#table-of-contents)
|
32
32
|
- [Gem installation](#gem-installation)
|
33
33
|
- [Setup](#setup)
|
34
|
+
- [Supported ORMs](#supported-orms)
|
35
|
+
- [ActiveRecord](#active-record)
|
36
|
+
- [Sequel](#sequel)
|
34
37
|
- [Model configuration](#model-configuration)
|
35
38
|
- [Activity fields](#activity-fields)
|
36
39
|
- [Activity extra data](#activity-extra-data)
|
40
|
+
- [Activity creation](#activity-creation)
|
37
41
|
- [Feed manager](#feed-manager)
|
42
|
+
- [Showing the newsfeed](#showing-the-newsfeed)
|
43
|
+
- [Activity enrichment](#activity-enrichment)
|
44
|
+
- [Templating](#templating)
|
45
|
+
- [Pagination](#pagination)
|
46
|
+
- [Disable model tracking](#disable-model-tracking)
|
47
|
+
- [Running specs](#running-specs)
|
38
48
|
|
39
49
|
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
40
50
|
|
@@ -55,13 +65,51 @@ Login with Github on getstream.io and get your ```api_key``` and ```api_secret``
|
|
55
65
|
|
56
66
|
Then you can add the StreamRails configuration in ```config/initializers/stream_rails.rb```
|
57
67
|
|
58
|
-
```
|
68
|
+
```ruby
|
59
69
|
require 'stream_rails'
|
60
70
|
|
61
71
|
StreamRails.configure do |config|
|
62
72
|
config.api_key = "YOUR API KEY"
|
63
73
|
config.api_secret = "YOUR API SECRET"
|
64
|
-
config.timeout = 30
|
74
|
+
config.timeout = 30 # Optional, defaults to 3
|
75
|
+
config.location = 'us-east' # Optional, defaults to 'us-east'
|
76
|
+
# If you use custom feed names, e.g.: timeline_flat, timeline_aggregated,
|
77
|
+
# use this, otherwise omit:
|
78
|
+
config.news_feeds = { flat: "timeline_flat", aggregated: "timeline_aggregated" }
|
79
|
+
end
|
80
|
+
```
|
81
|
+
|
82
|
+
###Supported ORMs
|
83
|
+
|
84
|
+
####ActiveRecord
|
85
|
+
|
86
|
+
The integration will look as follows:
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
class Pin < ActiveRecord::Base
|
90
|
+
include StreamRails::Activity
|
91
|
+
as_activity
|
92
|
+
|
93
|
+
def activity_object
|
94
|
+
self.item
|
95
|
+
end
|
96
|
+
end
|
97
|
+
```
|
98
|
+
|
99
|
+
####Sequel
|
100
|
+
|
101
|
+
Please, use Sequel `~4`.
|
102
|
+
|
103
|
+
The integration will look as follows:
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
class Pin < Sequel::Model
|
107
|
+
include StreamRails::Activity
|
108
|
+
as_activity
|
109
|
+
|
110
|
+
def activity_object
|
111
|
+
self.item
|
112
|
+
end
|
65
113
|
end
|
66
114
|
```
|
67
115
|
|
@@ -141,6 +189,32 @@ class Pin < ActiveRecord::Base
|
|
141
189
|
end
|
142
190
|
```
|
143
191
|
|
192
|
+
####Activity creation
|
193
|
+
|
194
|
+
If you want to control when to create an activity you should implement
|
195
|
+
the ```#activity_should_sync?``` method in your model.
|
196
|
+
|
197
|
+
```ruby
|
198
|
+
class Pin < ActiveRecord::Base
|
199
|
+
belongs_to :author
|
200
|
+
belongs_to :item
|
201
|
+
|
202
|
+
include StreamRails::Activity
|
203
|
+
as_activity
|
204
|
+
|
205
|
+
def activity_should_sync?
|
206
|
+
self.published
|
207
|
+
end
|
208
|
+
|
209
|
+
def activity_object
|
210
|
+
self.item
|
211
|
+
end
|
212
|
+
|
213
|
+
end
|
214
|
+
```
|
215
|
+
|
216
|
+
This will create an activity only when `self.published` is true.
|
217
|
+
|
144
218
|
###Feed manager
|
145
219
|
|
146
220
|
```stream_rails``` comes with a Feed Manager class that helps with all common feed operations. You can get an instance of the manager with ```StreamRails.feed_manager```.
|
@@ -292,6 +366,16 @@ eg. adds the extra_var to the partial scope
|
|
292
366
|
<%= render_activity activity, :locals => {:extra_var => 42} %>
|
293
367
|
```
|
294
368
|
|
369
|
+
####Pagination
|
370
|
+
|
371
|
+
For simple pagination you can use the [stream-ruby API](https://github.com/getstream/stream-ruby),
|
372
|
+
as follows in your controller:
|
373
|
+
|
374
|
+
```ruby
|
375
|
+
StreamRails.feed_manager.get_news_feeds(current_user.id)[:flat] # Returns a Stream::Feed object
|
376
|
+
results = feed.get(limit: 5, offset: 5)['results']
|
377
|
+
```
|
378
|
+
|
295
379
|
### Disable model tracking
|
296
380
|
|
297
381
|
You can disable model tracking (eg. when you run tests) via StreamRails.configure
|
@@ -301,3 +385,11 @@ require 'stream_rails'
|
|
301
385
|
|
302
386
|
StreamRails.enabled = false
|
303
387
|
```
|
388
|
+
|
389
|
+
###Running specs
|
390
|
+
|
391
|
+
From the project root directory:
|
392
|
+
|
393
|
+
```
|
394
|
+
./bin/run_tests.sh
|
395
|
+
```
|
data/lib/stream_rails.rb
CHANGED
@@ -9,17 +9,17 @@ module StreamRails
|
|
9
9
|
|
10
10
|
autoload :Activity
|
11
11
|
autoload :Config
|
12
|
-
autoload :FeedManager,
|
12
|
+
autoload :FeedManager, 'stream_rails/feed_manager'
|
13
13
|
autoload :Renderable
|
14
14
|
autoload :VERSION
|
15
15
|
|
16
16
|
def self.client
|
17
17
|
Stream::Client.new(
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
:
|
22
|
-
:
|
18
|
+
config.api_key,
|
19
|
+
config.api_secret,
|
20
|
+
config.api_site_id,
|
21
|
+
location: config.location,
|
22
|
+
default_timeout: config.timeout
|
23
23
|
)
|
24
24
|
end
|
25
25
|
|
@@ -38,12 +38,12 @@ module StreamRails
|
|
38
38
|
# Enabled by default.
|
39
39
|
# @return [Boolean]
|
40
40
|
def self.enabled?
|
41
|
-
|
41
|
+
StreamRails.config.enabled
|
42
42
|
end
|
43
43
|
|
44
44
|
# Returns StreamRails's configuration object.
|
45
45
|
def self.feed_manager
|
46
|
-
@feed_manager ||= StreamRails::FeedManager.new(
|
46
|
+
@feed_manager ||= StreamRails::FeedManager.new(client, config.feed_configs)
|
47
47
|
end
|
48
48
|
|
49
49
|
# Lets you set global configuration options.
|
@@ -57,10 +57,9 @@ module StreamRails
|
|
57
57
|
# config.location = "us-east"
|
58
58
|
# config.enabled = true
|
59
59
|
# end
|
60
|
-
def self.configure(&
|
60
|
+
def self.configure(&_block)
|
61
61
|
yield(config) if block_given?
|
62
62
|
end
|
63
|
-
|
64
63
|
end
|
65
64
|
|
66
65
|
require 'stream_rails/utils/view_helpers'
|
@@ -2,10 +2,9 @@ require 'active_record'
|
|
2
2
|
require 'stream_rails/sync_policies'
|
3
3
|
|
4
4
|
module StreamRails
|
5
|
-
|
6
5
|
class << self
|
7
6
|
def create_reference(record)
|
8
|
-
if record.is_a?
|
7
|
+
if record.is_a?(ActiveRecord::Base) || (Object.const_defined?('Sequel') && record.is_a?(Sequel::Model))
|
9
8
|
"#{record.class.model_name}:#{record.id}"
|
10
9
|
else
|
11
10
|
record.to_s unless record.nil?
|
@@ -14,34 +13,29 @@ module StreamRails
|
|
14
13
|
end
|
15
14
|
|
16
15
|
module ClassMethods
|
17
|
-
|
18
16
|
def as_activity(opts = {})
|
19
|
-
default_opts = {:
|
17
|
+
default_opts = { track_deletes: true, sync_policy: nil }
|
20
18
|
options = default_opts.merge(opts)
|
21
19
|
if options[:sync_policy].nil?
|
22
20
|
include StreamRails::SyncPolicy::SyncCreate
|
23
|
-
if options[:track_deletes]
|
24
|
-
include StreamRails::SyncPolicy::SyncDestroy
|
25
|
-
end
|
21
|
+
include StreamRails::SyncPolicy::SyncDestroy if options[:track_deletes]
|
26
22
|
else
|
27
23
|
include options[:sync_policy]
|
28
24
|
end
|
29
25
|
end
|
30
|
-
|
31
26
|
end
|
32
27
|
|
33
28
|
module Activity
|
34
|
-
|
35
|
-
def self.included base
|
29
|
+
def self.included(base)
|
36
30
|
base.extend ClassMethods
|
37
31
|
end
|
38
32
|
|
39
33
|
def activity_owner_id
|
40
|
-
|
34
|
+
activity_actor.id
|
41
35
|
end
|
42
36
|
|
43
37
|
def activity_actor
|
44
|
-
|
38
|
+
user
|
45
39
|
end
|
46
40
|
|
47
41
|
def activity_owner_feed
|
@@ -49,11 +43,11 @@ module StreamRails
|
|
49
43
|
end
|
50
44
|
|
51
45
|
def activity_actor_id
|
52
|
-
StreamRails.create_reference(
|
46
|
+
StreamRails.create_reference(activity_actor)
|
53
47
|
end
|
54
48
|
|
55
49
|
def activity_object
|
56
|
-
|
50
|
+
fail NotImplementedError, 'Activity models must define `#activity_object`'
|
57
51
|
end
|
58
52
|
|
59
53
|
def activity_verb
|
@@ -61,7 +55,7 @@ module StreamRails
|
|
61
55
|
end
|
62
56
|
|
63
57
|
def activity_object_id
|
64
|
-
StreamRails.create_reference(
|
58
|
+
StreamRails.create_reference(activity_object)
|
65
59
|
end
|
66
60
|
|
67
61
|
def activity_foreign_id
|
@@ -76,22 +70,23 @@ module StreamRails
|
|
76
70
|
end
|
77
71
|
|
78
72
|
def activity_time
|
79
|
-
|
73
|
+
created_at.iso8601
|
74
|
+
end
|
75
|
+
|
76
|
+
def activity_should_sync?
|
77
|
+
true
|
80
78
|
end
|
81
79
|
|
82
80
|
def create_activity
|
83
81
|
activity = {
|
84
|
-
:
|
85
|
-
:
|
86
|
-
:
|
87
|
-
:
|
88
|
-
:
|
82
|
+
actor: activity_actor_id,
|
83
|
+
verb: activity_verb,
|
84
|
+
object: activity_object_id,
|
85
|
+
foreign_id: activity_foreign_id,
|
86
|
+
time: activity_time
|
89
87
|
}
|
90
|
-
|
91
|
-
|
92
|
-
end
|
93
|
-
activity.merge(self.activity_extra_data)
|
88
|
+
activity[:to] = activity_notify.map(&:id) unless activity_notify.nil?
|
89
|
+
activity.merge(activity_extra_data)
|
94
90
|
end
|
95
|
-
|
96
91
|
end
|
97
92
|
end
|
data/lib/stream_rails/config.rb
CHANGED
@@ -7,24 +7,23 @@ module StreamRails
|
|
7
7
|
attr_accessor :api_site_id
|
8
8
|
attr_accessor :enabled
|
9
9
|
attr_accessor :timeout
|
10
|
-
|
10
|
+
|
11
11
|
attr_accessor :news_feeds
|
12
12
|
attr_accessor :notification_feed
|
13
13
|
attr_accessor :user_feed
|
14
14
|
|
15
15
|
def initialize
|
16
16
|
@enabled = true
|
17
|
-
@news_feeds = {:
|
18
|
-
@notification_feed
|
19
|
-
@user_feed
|
17
|
+
@news_feeds = { flat: 'flat', aggregated: 'aggregated' }
|
18
|
+
@notification_feed = 'notification'
|
19
|
+
@user_feed = 'user'
|
20
20
|
@timeout = 3
|
21
21
|
end
|
22
22
|
|
23
23
|
def feed_configs
|
24
|
-
|
25
|
-
:notification_feed
|
26
|
-
:user_feed
|
24
|
+
{ news_feeds: @news_feeds,
|
25
|
+
notification_feed: @notification_feed,
|
26
|
+
user_feed: @user_feed }
|
27
27
|
end
|
28
|
-
|
29
28
|
end
|
30
29
|
end
|
data/lib/stream_rails/enrich.rb
CHANGED
@@ -1,18 +1,17 @@
|
|
1
1
|
require 'active_record'
|
2
2
|
|
3
3
|
module StreamRails
|
4
|
-
|
5
4
|
class ActivityResult < Hash
|
6
5
|
attr_accessor :enriched
|
7
6
|
attr_reader :failed_to_enrich
|
8
7
|
|
9
8
|
def initialize
|
10
|
-
@failed_to_enrich =
|
9
|
+
@failed_to_enrich = {}
|
11
10
|
super
|
12
11
|
end
|
13
12
|
|
14
13
|
def from_activity(h)
|
15
|
-
|
14
|
+
merge(h)
|
16
15
|
end
|
17
16
|
|
18
17
|
def enriched?
|
@@ -26,23 +25,17 @@ module StreamRails
|
|
26
25
|
def track_not_enriched_field(field, value = nil)
|
27
26
|
@failed_to_enrich[field] = value
|
28
27
|
end
|
29
|
-
|
30
28
|
end
|
31
29
|
|
32
30
|
class Enrich
|
33
|
-
|
34
31
|
def initialize(fields = nil)
|
35
|
-
|
32
|
+
@fields = fields || [:actor, :object]
|
36
33
|
end
|
37
34
|
|
38
35
|
def model_field?(field_value)
|
39
|
-
|
40
|
-
return false
|
41
|
-
end
|
36
|
+
return false unless field_value.respond_to?('split')
|
42
37
|
bits = field_value.split(':')
|
43
|
-
if bits.length < 2
|
44
|
-
return false
|
45
|
-
end
|
38
|
+
return false if bits.length < 2
|
46
39
|
begin
|
47
40
|
bits[0].classify.constantize
|
48
41
|
rescue NameError
|
@@ -53,28 +46,28 @@ module StreamRails
|
|
53
46
|
end
|
54
47
|
|
55
48
|
def enrich_activities(activities)
|
56
|
-
references =
|
57
|
-
objects =
|
58
|
-
|
49
|
+
references = collect_references(activities)
|
50
|
+
objects = retrieve_objects(references)
|
51
|
+
inject_objects(activities, objects)
|
59
52
|
end
|
60
53
|
|
61
54
|
def enrich_aggregated_activities(aggregated_activities)
|
62
|
-
references =
|
55
|
+
references = {}
|
63
56
|
aggregated_activities.each do |aggregated|
|
64
|
-
refs =
|
65
|
-
references = references.merge(refs){|
|
57
|
+
refs = collect_references(aggregated['activities'])
|
58
|
+
references = references.merge(refs) { |_key, v1, v2| v1.merge(v2) }
|
66
59
|
end
|
67
|
-
objects =
|
60
|
+
objects = retrieve_objects(references)
|
68
61
|
aggregated_activities.each do |aggregated|
|
69
|
-
aggregated['activities'] =
|
62
|
+
aggregated['activities'] = inject_objects(aggregated['activities'], objects)
|
70
63
|
end
|
71
|
-
aggregated_activities
|
64
|
+
create_activity_results(aggregated_activities)
|
72
65
|
end
|
73
66
|
|
74
67
|
def collect_references(activities)
|
75
|
-
model_refs = Hash.new{ |h,k| h[k] =
|
68
|
+
model_refs = Hash.new { |h, k| h[k] = {} }
|
76
69
|
activities.each do |activity|
|
77
|
-
activity.select{|k,
|
70
|
+
activity.select { |k, _v| @fields.include? k.to_sym }.each do |_field, value|
|
78
71
|
next unless self.model_field?(value)
|
79
72
|
model, id = value.split(':')
|
80
73
|
model_refs[model][id] = 0
|
@@ -84,24 +77,24 @@ module StreamRails
|
|
84
77
|
end
|
85
78
|
|
86
79
|
def retrieve_objects(references)
|
87
|
-
Hash[references.map{ |model, ids| [model, Hash[model.classify.constantize.where(id: ids.keys).map {|i| [i.id.to_s, i]}]
|
80
|
+
Hash[references.map { |model, ids| [model, Hash[model.classify.constantize.where(id: ids.keys).map { |i| [i.id.to_s, i] }]] }]
|
88
81
|
end
|
89
82
|
|
90
83
|
def inject_objects(activities, objects)
|
91
|
-
activities
|
92
|
-
|
93
|
-
activity.select{|k,v| @fields.include? k.to_sym}.each do |field, value|
|
84
|
+
create_activity_results(activities).each do |activity|
|
85
|
+
activity.select { |k, _v| @fields.include? k.to_sym }.each do |field, value|
|
94
86
|
next unless self.model_field?(value)
|
95
87
|
model, id = value.split(':')
|
96
88
|
activity[field] = objects[model][id] || value
|
97
|
-
if objects[model][id].nil?
|
98
|
-
activity.track_not_enriched_field(field, value)
|
99
|
-
end
|
89
|
+
activity.track_not_enriched_field(field, value) if objects[model][id].nil?
|
100
90
|
end
|
101
91
|
end
|
102
|
-
activities
|
103
92
|
end
|
104
93
|
|
105
|
-
|
94
|
+
private
|
106
95
|
|
96
|
+
def create_activity_results(activities)
|
97
|
+
return activities.map { |a| ActivityResult.new.from_activity(a) }
|
98
|
+
end
|
99
|
+
end
|
107
100
|
end
|
@@ -3,11 +3,11 @@ module StreamRails
|
|
3
3
|
class FeedManager
|
4
4
|
attr_reader :client
|
5
5
|
|
6
|
-
def initialize(client, opts={})
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
def initialize(client, opts = {})
|
7
|
+
@client = client
|
8
|
+
@user_feed = opts[:user_feed]
|
9
|
+
@news_feeds = opts[:news_feeds]
|
10
|
+
@notification_feed = opts[:notification_feed]
|
11
11
|
end
|
12
12
|
|
13
13
|
def get_user_feed(user_id)
|
@@ -15,7 +15,7 @@ module StreamRails
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def get_news_feeds(user_id)
|
18
|
-
Hash[@news_feeds.map{ |
|
18
|
+
Hash[@news_feeds.map { |feed_name, feed_slug| [feed_name, get_feed(feed_slug, user_id)] }]
|
19
19
|
end
|
20
20
|
|
21
21
|
def get_notification_feed(user_id)
|
@@ -27,39 +27,38 @@ module StreamRails
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def follow_user(user_id, target_id)
|
30
|
-
|
30
|
+
return unless StreamRails.enabled?
|
31
|
+
target_feed = get_user_feed(target_id)
|
31
32
|
@news_feeds.each do |_, feed|
|
32
|
-
news_feed =
|
33
|
+
news_feed = get_feed(feed, user_id)
|
33
34
|
news_feed.follow(target_feed.slug, target_feed.user_id)
|
34
35
|
end
|
35
36
|
end
|
36
37
|
|
37
38
|
def unfollow_user(user_id, target_id)
|
38
|
-
|
39
|
+
return unless StreamRails.enabled?
|
40
|
+
target_feed = get_user_feed(target_id)
|
39
41
|
@news_feeds.each do |_, feed|
|
40
|
-
news_feed =
|
42
|
+
news_feed = get_feed(feed, user_id)
|
41
43
|
news_feed.unfollow(target_feed.slug, target_feed.user_id)
|
42
44
|
end
|
43
45
|
end
|
44
46
|
|
45
47
|
def get_owner_feed(instance)
|
46
|
-
|
48
|
+
get_feed(instance.activity_owner_feed, instance.activity_owner_id)
|
47
49
|
end
|
48
50
|
|
49
51
|
def created_activity(instance)
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
52
|
+
return unless StreamRails.enabled? && instance.activity_should_sync?
|
53
|
+
activity = instance.create_activity
|
54
|
+
feed = get_owner_feed(instance)
|
55
|
+
feed.add_activity(activity)
|
55
56
|
end
|
56
57
|
|
57
58
|
def destroyed_activity(instance)
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
end
|
59
|
+
return unless StreamRails.enabled?
|
60
|
+
feed = get_owner_feed(instance)
|
61
|
+
feed.remove(instance.activity_foreign_id, true)
|
62
62
|
end
|
63
|
-
|
64
63
|
end
|
65
64
|
end
|
data/lib/stream_rails/railtie.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
module StreamRails
|
2
2
|
# Provides logic for rendering activities. (different templates per activity verb).
|
3
3
|
module Renderable
|
4
|
-
|
5
4
|
class << self
|
6
|
-
|
7
5
|
def render(activity, context, params = {})
|
8
|
-
aggregated = activity.
|
6
|
+
aggregated = activity.key? 'activities'
|
9
7
|
partial = partial_path(activity, aggregated, *params.values_at(:prefix, :partial, :partial_root))
|
10
8
|
layout = layout_path(*params.values_at(:layout, :layout_root))
|
11
9
|
locals = prepare_locals(activity, params)
|
@@ -27,7 +25,7 @@ module StreamRails
|
|
27
25
|
end
|
28
26
|
|
29
27
|
def render_aggregated(activity, context, params)
|
30
|
-
if !activity['activities'].map {|a| !a.enriched?}.all?
|
28
|
+
if !activity['activities'].map { |a| !a.enriched? }.all?
|
31
29
|
context.render params
|
32
30
|
else
|
33
31
|
first_activity = activity['activities'][0]
|
@@ -37,30 +35,30 @@ module StreamRails
|
|
37
35
|
end
|
38
36
|
|
39
37
|
def layout_path(path = nil, root = nil)
|
40
|
-
path.nil?
|
38
|
+
path.nil? && return
|
41
39
|
root ||= 'layouts'
|
42
40
|
select_path path, root
|
43
41
|
end
|
44
42
|
|
45
43
|
def partial_path(activity, aggregated, prefix = '', path = nil, root = nil)
|
46
|
-
root ||= (
|
44
|
+
root ||= (aggregated ? 'aggregated_activity' : 'activity')
|
47
45
|
path ||= "#{activity['verb']}".downcase
|
48
46
|
path = "#{prefix}_#{path}" if prefix
|
49
47
|
select_path path, root
|
50
48
|
end
|
51
49
|
|
52
50
|
def prepare_locals(activity, params)
|
53
|
-
locals = params.delete(:locals) ||
|
51
|
+
locals = params.delete(:locals) || {}
|
54
52
|
locals.merge\
|
55
53
|
activity: activity,
|
56
54
|
parameters: params
|
57
55
|
end
|
58
56
|
|
59
57
|
private
|
60
|
-
|
58
|
+
|
59
|
+
def select_path(path, root)
|
61
60
|
[root, path].map(&:to_s).join('/')
|
62
61
|
end
|
63
62
|
end
|
64
63
|
end
|
65
|
-
|
66
64
|
end
|
@@ -1,40 +1,55 @@
|
|
1
1
|
module StreamRails
|
2
|
-
|
3
2
|
module SyncPolicy
|
4
|
-
|
5
3
|
module SyncCreate
|
6
|
-
|
7
4
|
def self.included(base)
|
8
|
-
base.
|
5
|
+
if base.respond_to? :after_commit
|
6
|
+
base.after_commit :add_to_feed, on: :create
|
7
|
+
elsif Object.const_defined?('Sequel') && base < Sequel::Model
|
8
|
+
base.class_eval do
|
9
|
+
define_method(:_after_create) do |*args|
|
10
|
+
super(*args)
|
11
|
+
add_to_feed
|
12
|
+
end
|
13
|
+
end
|
14
|
+
else
|
15
|
+
fail 'Your ORM is not supported'
|
16
|
+
end
|
9
17
|
end
|
10
18
|
|
11
19
|
private
|
20
|
+
|
12
21
|
def add_to_feed
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
raise
|
18
|
-
end
|
22
|
+
StreamRails.feed_manager.created_activity(self)
|
23
|
+
rescue StandardError => e
|
24
|
+
StreamRails.logger.error "Something went wrong creating an activity: #{e}"
|
25
|
+
raise
|
19
26
|
end
|
20
27
|
end
|
21
28
|
|
22
29
|
module SyncDestroy
|
23
|
-
|
24
30
|
def self.included(base)
|
25
|
-
base.
|
31
|
+
if base.respond_to? :after_commit
|
32
|
+
base.after_commit :remove_from_feed, on: :destroy
|
33
|
+
elsif Object.const_defined?('Sequel') && base < Sequel::Model
|
34
|
+
base.instance_eval do
|
35
|
+
define_method(:before_destroy) do |*args|
|
36
|
+
remove_from_feed
|
37
|
+
super(*args)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
else
|
41
|
+
fail 'Your ORM is not supported'
|
42
|
+
end
|
26
43
|
end
|
27
44
|
|
28
45
|
private
|
46
|
+
|
29
47
|
def remove_from_feed
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
raise
|
35
|
-
end
|
48
|
+
StreamRails.feed_manager.destroyed_activity(self)
|
49
|
+
rescue StandardError => e
|
50
|
+
StreamRails.logger.error "Something went wrong deleting an activity: #{e}"
|
51
|
+
raise
|
36
52
|
end
|
37
53
|
end
|
38
|
-
|
39
54
|
end
|
40
55
|
end
|
@@ -3,12 +3,13 @@ module StreamRails
|
|
3
3
|
# Module extending ActionView::Base and adding `render_activity` helper.
|
4
4
|
module ViewHelpers
|
5
5
|
# View helper for rendering an activity
|
6
|
-
def render_activity
|
6
|
+
def render_activity(activity, options = {})
|
7
7
|
Renderable.render(activity, self, options)
|
8
8
|
end
|
9
|
+
|
9
10
|
# View helper for rendering many activities
|
10
|
-
def render_activities
|
11
|
-
activities.map {|activity| Renderable.render(activity, self, options.dup) }.join.html_safe
|
11
|
+
def render_activities(activities, options = {})
|
12
|
+
activities.map { |activity| Renderable.render(activity, self, options.dup) }.join.html_safe
|
12
13
|
end
|
13
14
|
end
|
14
15
|
ActionView::Base.class_eval { include ViewHelpers }
|
data/lib/stream_rails/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module StreamRails
|
2
|
-
VERSION = '2.
|
3
|
-
end
|
2
|
+
VERSION = '2.4.0'
|
3
|
+
end
|
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.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tommaso Barbugli
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 2.2.
|
47
|
+
version: 2.2.5
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 2.2.
|
54
|
+
version: 2.2.5
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: activerecord
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -136,6 +136,20 @@ dependencies:
|
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: 0.7.1
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: sequel
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '4.29'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '4.29'
|
139
153
|
description:
|
140
154
|
email: tbarbugli@gmail.com
|
141
155
|
executables: []
|