stream_rails 2.6.6 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 32133621350213716900e311c9d4b9b5321f4b9de8c5743826baf986437f5f86
4
- data.tar.gz: c3150a813bb1633373ccd4e10cef820d251095fc6f2885568b36d63cc4e0dd62
3
+ metadata.gz: 12af4b32dde33e9df2997ad8d9e92d7e1c912478d72db04bf949377dbe56646a
4
+ data.tar.gz: b6619f2ecaf1fb5b21251eec60b117386dfbc4622ffe1a71a5164506d172d809
5
5
  SHA512:
6
- metadata.gz: 0bde40e704677f17be82ad11c7a0c7e7db9749692e5a3e8b3f91b8416c1304d4d154ce4d9caf39f03b72eb4fe871cb4a0fdbf08f8f97bfba3138610ea6b4233e
7
- data.tar.gz: 8445326c9e9fd66e3fda414b4430bbadf28ef340e3b1b98dfcf8d39c2f882844cc880c4907f04055810043acf921ef7308471a34743d63b20426573d63a5c327
6
+ metadata.gz: 4bd338ff891bca9426862b0996b19e6beca617662597b8b66c71995895a64a6aadb986f27c539a49e9fdf33bb5b9688f5f7393a37edd03d2eb56b2892047232b
7
+ data.tar.gz: 328cd1ce3ba75efefcfdf21828c2608dcd1c63428a238c9c647e21b612a567b1d23c810f8a79d08d51754cc48241076a3c0421d9ed3eb0cc0128e6d71ee338b1
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014-2017 Stream.io Inc, and individual contributors.
1
+ Copyright (c) 2014-2021 Stream.io Inc, and individual contributors.
2
2
 
3
3
  All rights reserved.
4
4
 
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Stream Rails
2
2
 
3
- [![image](https://secure.travis-ci.org/GetStream/stream-rails.png?branch=master)](http://travis-ci.org/GetStream/stream-rails)
3
+ [![build](https://github.com/GetStream/stream-rails/workflows/build/badge.svg)](https://github.com/GetStream/stream-rails/actions)
4
4
  [![Gem Version](https://badge.fury.io/rb/stream_rails.svg)](http://badge.fury.io/rb/stream_rails)
5
5
 
6
6
  [stream-rails](https://github.com/GetStream/stream-rails) is a Ruby on Rails client for [Stream](https://getstream.io/).
@@ -67,10 +67,10 @@ gem 'stream_rails'
67
67
 
68
68
  This library is tested against and fully supports the following Rails versions:
69
69
 
70
- - 4.0
71
- - 4.2
72
70
  - 5.0
73
71
  - 5.2
72
+ - 6.0
73
+ - 6.1
74
74
 
75
75
  ### Setup
76
76
 
@@ -156,10 +156,36 @@ Everytime a Pin is created it will be stored in the feed of the user that create
156
156
 
157
157
  #### Activity fields
158
158
 
159
- 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:
159
+ 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 these methods:
160
160
 
161
161
  **#activity_object** the object of the activity (eg. an AR model instance)
162
- **#activity_actor** the actor performing the activity (defaults to `self.user`)
162
+
163
+ **#activity_actor** the actor performing the activity -- this value also provides the feed name and feed ID to which the activity will be added.
164
+
165
+ For example, let's say a Pin was a polymorphic class that could belong to either a user (e.g. `User` ID: 1) or a company (e.g. `Company` ID: 1). In that instance, the below code would post the pin either to the `user:1` feed or the `company:1` feed based on its owner.
166
+
167
+ ```ruby
168
+ class Pin < ActiveRecord::Base
169
+ belongs_to :owner, :polymorphic => true
170
+ belongs_to :item
171
+
172
+ include StreamRails::Activity
173
+ as_activity
174
+
175
+ def activity_actor
176
+ self.owner
177
+ end
178
+
179
+ def activity_object
180
+ self.item
181
+ end
182
+
183
+ end
184
+ ```
185
+
186
+ The `activity_actor` defaults to `self.user`
187
+
188
+
163
189
  **#activity_verb** the string representation of the verb (defaults to model class name)
164
190
 
165
191
  Here's a more complete example of the Pin class:
@@ -346,7 +372,7 @@ When you read data from feeds, a pin activity will look like this:
346
372
  ```
347
373
 
348
374
  This is far from ready for usage in your template. We call the process of loading the references from the database
349
- enrichment. An example is shown below:
375
+ "enrichment." An example is shown below:
350
376
 
351
377
  ```ruby
352
378
  enricher = StreamRails::Enrich.new
@@ -356,7 +382,7 @@ results = feed.get()['results']
356
382
  activities = enricher.enrich_activities(results)
357
383
  ```
358
384
 
359
- A similar method called enrich_aggregated_activities is available for aggregated feeds.
385
+ A similar method called `enrich_aggregated_activities` is available for aggregated feeds.
360
386
 
361
387
  ```ruby
362
388
  enricher = StreamRails::Enrich.new
@@ -434,7 +460,7 @@ For convenience we include a basic view:
434
460
 
435
461
  The `render_activity` view helper will render the activity by picking the partial `activity/_pin` for a pin activity, `aggregated_activity/_follow` for an aggregated activity with verb follow.
436
462
 
437
- The helper will automatically send `activity` to the local scope of the partial; additional parameters can be send as well as use different layouts, and prefix the name
463
+ The helper will automatically send `activity` to the local scope of the partial; additional parameters can be sent as well as use different layouts, and prefix the name
438
464
 
439
465
  e.g. renders the activity partial using the `small_activity` layout:
440
466
 
@@ -490,10 +516,10 @@ From the project root directory:
490
516
 
491
517
  ### Full documentation and Low level APIs access
492
518
 
493
- When needed you can also use the [low level Ruby API](https://github.com/getstream/stream-ruby) directly. Documentation is available at the [Stream website](https://getstream.io/docs/?language=ruby).
519
+ When needed you can also use the [low level Ruby API](https://github.com/getstream/stream-ruby) directly. Documentation is available at the [Stream website](https://getstream.io/activity-feeds/docs/?language=ruby).
494
520
 
495
521
  ### Copyright and License Information
496
522
 
497
- Copyright (c) 2014-2017 Stream.io Inc, and individual contributors. All rights reserved.
523
+ Copyright (c) 2014-2021 Stream.io Inc, and individual contributors. All rights reserved.
498
524
 
499
525
  See the file "LICENSE" for information on the history of this software, terms & conditions for usage, and a DISCLAIMER OF ALL WARRANTIES.
@@ -7,7 +7,7 @@ module StreamRails
7
7
  if record.is_a?(ActiveRecord::Base) || (Object.const_defined?('Sequel') && record.is_a?(Sequel::Model))
8
8
  "#{record.class.model_name}:#{record.id}"
9
9
  else
10
- record.to_s unless record.nil?
10
+ record&.to_s
11
11
  end
12
12
  end
13
13
  end
@@ -39,7 +39,7 @@ module StreamRails
39
39
  end
40
40
 
41
41
  def activity_owner_feed
42
- 'user'
42
+ activity_actor.class.name.downcase
43
43
  end
44
44
 
45
45
  def activity_actor_id
@@ -10,8 +10,8 @@ module StreamRails
10
10
  super
11
11
  end
12
12
 
13
- def from_activity(h)
14
- merge(h)
13
+ def from_activity(from)
14
+ merge(from)
15
15
  end
16
16
 
17
17
  def enriched?
@@ -31,7 +31,7 @@ module StreamRails
31
31
  attr_reader :fields
32
32
 
33
33
  def initialize(fields = nil)
34
- @fields = fields || [:actor, :object, :target]
34
+ @fields = fields || %i[actor object target]
35
35
  end
36
36
 
37
37
  def add_fields(new_fields)
@@ -47,9 +47,9 @@ module StreamRails
47
47
  begin
48
48
  model.classify.constantize
49
49
  rescue NameError
50
- return false
50
+ false
51
51
  else
52
- return true
52
+ true
53
53
  end
54
54
  end
55
55
 
@@ -77,6 +77,7 @@ module StreamRails
77
77
  activities.each do |activity|
78
78
  activity.select { |k, _v| @fields.include? k.to_sym }.each do |_field, value|
79
79
  next unless model_field?(value)
80
+
80
81
  model, _, id = value.rpartition(':')
81
82
  model_refs[model][id] = 0
82
83
  end
@@ -85,13 +86,18 @@ module StreamRails
85
86
  end
86
87
 
87
88
  def retrieve_objects(references)
88
- Hash[references.map { |model, ids| [model, Hash[model.classify.constantize.where(model.classify.constantize.primary_key => ids.keys).map { |i| [i.id.to_s, i] }]] }]
89
+ references.map do |model, ids|
90
+ [model, model.classify.constantize.where(model.classify.constantize.primary_key => ids.keys).map do |i|
91
+ [i.id.to_s, i]
92
+ end.to_h]
93
+ end.to_h
89
94
  end
90
95
 
91
96
  def inject_objects(activities, objects)
92
97
  create_activity_results(activities).each do |activity|
93
98
  activity.select { |k, _v| @fields.include? k.to_sym }.each do |field, value|
94
99
  next unless model_field?(value)
100
+
95
101
  model, _, id = value.rpartition(':')
96
102
  activity[field] = objects[model][id] || value
97
103
  activity.track_not_enriched_field(field, value) if objects[model][id].nil?
@@ -102,7 +108,7 @@ module StreamRails
102
108
  private
103
109
 
104
110
  def create_activity_results(activities)
105
- return activities.map { |a| ActivityResult.new.from_activity(a) }
111
+ activities.map { |a| ActivityResult.new.from_activity(a) }
106
112
  end
107
113
  end
108
114
  end
@@ -15,7 +15,7 @@ module StreamRails
15
15
  end
16
16
 
17
17
  def get_news_feeds(user_id)
18
- Hash[@news_feeds.map { |feed_name, feed_slug| [feed_name, get_feed(feed_slug, user_id)] }]
18
+ @news_feeds.transform_values { |feed_slug| get_feed(feed_slug, user_id) }
19
19
  end
20
20
 
21
21
  def get_notification_feed(user_id)
@@ -28,6 +28,7 @@ module StreamRails
28
28
 
29
29
  def follow_user(user_id, target_id)
30
30
  return unless StreamRails.enabled?
31
+
31
32
  target_feed = get_user_feed(target_id)
32
33
  @news_feeds.each do |_, feed|
33
34
  news_feed = get_feed(feed, user_id)
@@ -37,6 +38,7 @@ module StreamRails
37
38
 
38
39
  def unfollow_user(user_id, target_id)
39
40
  return unless StreamRails.enabled?
41
+
40
42
  target_feed = get_user_feed(target_id)
41
43
  @news_feeds.each do |_, feed|
42
44
  news_feed = get_feed(feed, user_id)
@@ -50,6 +52,7 @@ module StreamRails
50
52
 
51
53
  def created_activity(instance)
52
54
  return unless StreamRails.enabled? && instance.activity_should_sync?
55
+
53
56
  activity = instance.create_activity
54
57
  feed = get_owner_feed(instance)
55
58
  feed.add_activity(activity)
@@ -57,6 +60,7 @@ module StreamRails
57
60
 
58
61
  def destroyed_activity(instance)
59
62
  return unless StreamRails.enabled?
63
+
60
64
  feed = get_owner_feed(instance)
61
65
  feed.remove(instance.activity_foreign_id, true)
62
66
  end
@@ -4,5 +4,5 @@ module StreamRails
4
4
  class << self
5
5
  attr_accessor :logger
6
6
  end
7
- self.logger = Logger.new(STDOUT)
7
+ self.logger = Logger.new($stdout)
8
8
  end
@@ -20,17 +20,17 @@ module StreamRails
20
20
  context.render params
21
21
  else
22
22
  StreamRails.logger.warn "trying to display a non enriched activity #{activity.inspect} #{activity.failed_to_enrich}"
23
- return ''
23
+ ''
24
24
  end
25
25
  end
26
26
 
27
27
  def render_aggregated(activity, context, params)
28
- if !activity['activities'].map { |a| !a.enriched? }.all?
29
- context.render params
30
- else
28
+ if activity['activities'].map { |a| !a.enriched? }.all?
31
29
  first_activity = activity['activities'][0]
32
30
  StreamRails.logger.warn "trying to display a non enriched activity #{first_activity.inspect} #{first_activity.failed_to_enrich}"
33
- return ''
31
+ ''
32
+ else
33
+ context.render params
34
34
  end
35
35
  end
36
36
 
@@ -42,7 +42,7 @@ module StreamRails
42
42
 
43
43
  def partial_path(activity, aggregated, prefix = '', path = nil, root = nil)
44
44
  root ||= (aggregated ? 'aggregated_activity' : 'activity')
45
- path ||= "#{activity['verb']}".downcase
45
+ path ||= (activity['verb']).to_s.downcase
46
46
  path = "#{prefix}_#{path}" if prefix
47
47
  select_path path, root
48
48
  end
@@ -50,8 +50,8 @@ module StreamRails
50
50
  def prepare_locals(activity, params)
51
51
  locals = params.delete(:locals) || {}
52
52
  locals.merge\
53
- activity: activity,
54
- parameters: params
53
+ activity: activity,
54
+ parameters: params
55
55
  end
56
56
 
57
57
  private
@@ -1,3 +1,3 @@
1
1
  module StreamRails
2
- VERSION = '2.6.6'.freeze
2
+ VERSION = '3.0.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stream_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.6
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tommaso Barbugli
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-03-18 00:00:00.000000000 Z
13
+ date: 2021-03-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: actionpack
@@ -18,56 +18,56 @@ dependencies:
18
18
  requirements:
19
19
  - - ">="
20
20
  - !ruby/object:Gem::Version
21
- version: 3.0.0
21
+ version: 5.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
- version: 3.0.0
28
+ version: 5.0.0
29
29
  - !ruby/object:Gem::Dependency
30
- name: railties
30
+ name: activerecord
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
33
  - - ">="
34
34
  - !ruby/object:Gem::Version
35
- version: 3.0.0
35
+ version: 5.0.0
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
40
  - - ">="
41
41
  - !ruby/object:Gem::Version
42
- version: 3.0.0
42
+ version: 5.0.0
43
43
  - !ruby/object:Gem::Dependency
44
- name: stream-ruby
44
+ name: railties
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - "~>"
47
+ - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: '3.1'
49
+ version: 5.0.0
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
- - - "~>"
54
+ - - ">="
55
55
  - !ruby/object:Gem::Version
56
- version: '3.1'
56
+ version: 5.0.0
57
57
  - !ruby/object:Gem::Dependency
58
- name: activerecord
58
+ name: stream-ruby
59
59
  requirement: !ruby/object:Gem::Requirement
60
60
  requirements:
61
- - - ">="
61
+ - - "~>"
62
62
  - !ruby/object:Gem::Version
63
- version: 3.0.0
63
+ version: 4.0.1
64
64
  type: :runtime
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
- - - ">="
68
+ - - "~>"
69
69
  - !ruby/object:Gem::Version
70
- version: 3.0.0
70
+ version: 4.0.1
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: rake
73
73
  requirement: !ruby/object:Gem::Requirement
@@ -83,33 +83,33 @@ dependencies:
83
83
  - !ruby/object:Gem::Version
84
84
  version: '0'
85
85
  - !ruby/object:Gem::Dependency
86
- name: sqlite3
86
+ name: rspec
87
87
  requirement: !ruby/object:Gem::Requirement
88
88
  requirements:
89
89
  - - "~>"
90
90
  - !ruby/object:Gem::Version
91
- version: 1.3.13
91
+ version: '3.10'
92
92
  type: :development
93
93
  prerelease: false
94
94
  version_requirements: !ruby/object:Gem::Requirement
95
95
  requirements:
96
96
  - - "~>"
97
97
  - !ruby/object:Gem::Version
98
- version: 1.3.13
98
+ version: '3.10'
99
99
  - !ruby/object:Gem::Dependency
100
- name: rspec
100
+ name: sequel
101
101
  requirement: !ruby/object:Gem::Requirement
102
102
  requirements:
103
103
  - - "~>"
104
104
  - !ruby/object:Gem::Version
105
- version: '3.8'
105
+ version: '4.49'
106
106
  type: :development
107
107
  prerelease: false
108
108
  version_requirements: !ruby/object:Gem::Requirement
109
109
  requirements:
110
110
  - - "~>"
111
111
  - !ruby/object:Gem::Version
112
- version: '3.8'
112
+ version: '4.49'
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: simplecov
115
115
  requirement: !ruby/object:Gem::Requirement
@@ -125,19 +125,19 @@ dependencies:
125
125
  - !ruby/object:Gem::Version
126
126
  version: 0.16.1
127
127
  - !ruby/object:Gem::Dependency
128
- name: sequel
128
+ name: sqlite3
129
129
  requirement: !ruby/object:Gem::Requirement
130
130
  requirements:
131
131
  - - "~>"
132
132
  - !ruby/object:Gem::Version
133
- version: '4.49'
133
+ version: 1.3.13
134
134
  type: :development
135
135
  prerelease: false
136
136
  version_requirements: !ruby/object:Gem::Requirement
137
137
  requirements:
138
138
  - - "~>"
139
139
  - !ruby/object:Gem::Version
140
- version: '4.49'
140
+ version: 1.3.13
141
141
  description:
142
142
  email: support@getstream.io
143
143
  executables: []
@@ -171,15 +171,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
171
171
  requirements:
172
172
  - - ">="
173
173
  - !ruby/object:Gem::Version
174
- version: 1.9.2
174
+ version: 2.5.5
175
175
  required_rubygems_version: !ruby/object:Gem::Requirement
176
176
  requirements:
177
177
  - - ">="
178
178
  - !ruby/object:Gem::Version
179
179
  version: '0'
180
180
  requirements: []
181
- rubyforge_project:
182
- rubygems_version: 2.7.8
181
+ rubygems_version: 3.1.2
183
182
  signing_key:
184
183
  specification_version: 4
185
184
  summary: A gem that provides a client interface for getstream.io