stream_rails 2.5.0 → 2.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0d3432a8955f14a1c5bc68728636624f4e32feb7
4
- data.tar.gz: 07c4acdc2ece3b24277052b51547a07095f335fa
3
+ metadata.gz: b2be56f2aac225bde0b2b22a82a981fee33411ef
4
+ data.tar.gz: 9606304c21188e469f650edb1aba96147a9a3f59
5
5
  SHA512:
6
- metadata.gz: a03aafb8e658cc99d5808dc1ca1d56e2012ae647eefd26bd126b4b63a6ca74f3d026ea253bb56027a888e89e54192c74a4ddd4227c3981ce8e00999baa8a998f
7
- data.tar.gz: 791fd74c07194ecbf7fdff17419531b1b71cdadc841a6e3df751c84bf34d2c0568c3b9ae7a8e6bac6d9b47b8ad3af60e7fe81ea1ce94e05c0e677f1e8ca68701
6
+ metadata.gz: ff2835f8309e581328db198c6e044ea47dfc2333936bcf3d98203c1dc638e1c53af498657c3452098f3662786461926679f08a678d96f22a997ddc95d9254520
7
+ data.tar.gz: 603245bbc79e09e0b57e38c29157b8e7981102f84c26bb94acdd46b96d855779f03b532f6e24d3bf8c0523a6791a66e56cd6231c5ecb16c2c9e2c51aa24f9a37
data/README.md CHANGED
@@ -22,7 +22,7 @@ What you can build:
22
22
 
23
23
  You can check out our example app built using this library on Github [https://github.com/GetStream/Stream-Example-Rails](https://github.com/GetStream/Stream-Example-Rails)
24
24
 
25
- ###Table of Contents
25
+ ### Table of Contents
26
26
 
27
27
  <!-- START doctoc generated TOC please keep comment here to allow auto update -->
28
28
  <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
@@ -62,7 +62,6 @@ or in your Gemfile:
62
62
  gem 'stream_rails'
63
63
  ```
64
64
 
65
-
66
65
  ### Setup
67
66
 
68
67
  Login with Github on getstream.io and get your ```api_key``` and ```api_secret``` from your app configuration (Dashboard screen).
@@ -86,9 +85,9 @@ StreamRails.configure do |config|
86
85
  end
87
86
  ```
88
87
 
89
- ###Supported ORMs
88
+ ### Supported ORMs
90
89
 
91
- ####ActiveRecord
90
+ #### ActiveRecord
92
91
 
93
92
  The integration will look as follows:
94
93
 
@@ -103,7 +102,7 @@ class Pin < ActiveRecord::Base
103
102
  end
104
103
  ```
105
104
 
106
- ####Sequel
105
+ #### Sequel
107
106
 
108
107
  Please, use Sequel `~4`.
109
108
 
@@ -321,7 +320,7 @@ StreamRails.feed_manager.follow_user(user_id, target_id)
321
320
 
322
321
  ### Showing the newsfeed
323
322
 
324
- ####Activity enrichment
323
+ #### Activity enrichment
325
324
 
326
325
  When you read data from feeds, a pin activity will look like this:
327
326
 
@@ -329,7 +328,8 @@ When you read data from feeds, a pin activity will look like this:
329
328
  {"actor": "User:1", "verb": "like", "object": "Item:42"}
330
329
  ```
331
330
 
332
- 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:
331
+ This is far from ready for usage in your template. We call the process of loading the references from the database
332
+ enrichment. An example is shown below:
333
333
 
334
334
  ```ruby
335
335
  enricher = StreamRails::Enrich.new
@@ -339,7 +339,56 @@ results = feed.get()['results']
339
339
  activities = enricher.enrich_activities(results)
340
340
  ```
341
341
 
342
- ####Templating
342
+ If you have additional metadata in your activity (by overriding `activity_extra_data` in the class where you add the
343
+ Stream Activity mixin), you can also enrich that field's data by doing the following:
344
+
345
+ Step One: override the `activity_extra_data` method from our mixin:
346
+ ```ruby
347
+ class Pin < ActiveRecord::Base
348
+ include StreamRails::Activity
349
+ as_activity
350
+
351
+ attr_accessor :extra_data
352
+
353
+ def activity_object
354
+ self.item
355
+ end
356
+
357
+ # override this method to add metadata to your activity
358
+ def activity_extra_data
359
+ @extra_data
360
+ end
361
+ end
362
+ ```
363
+
364
+ Now we'll create a 'pin' object which has a `location` metadata field. In this example, we will also have a
365
+ `location` table and model, and we set up our metadata in the `extra_data` field. It is important that the
366
+ symbol of the metadata as well as the value of the meta data match this pattern. The left half of the
367
+ `string:string` metadata value when split on `:` must also match the name of the model.
368
+
369
+ We must also tell the enricher to also fetch locations when looking through our activities
370
+
371
+ ```ruby
372
+ boulder = Location.new
373
+ boulder.name = "Boulder, CO"
374
+ boulder.save!
375
+
376
+ # tell the enricher to also do a lookup on the `location` model
377
+ enricher.add_fields([:location])
378
+
379
+ pin = Pin.new
380
+ pin.user = @tom
381
+ pin.extra_data = {:location => "location:#{@boulder.id}"}
382
+ ```
383
+
384
+ When we retrieve the activity later, the enrichment process will include our `location` model as well, giving us
385
+ access to attributes and methods of the location model:
386
+ ```ruby
387
+ place = activity[:location].name
388
+ # Boulder, CO
389
+ ```
390
+
391
+ #### Templating
343
392
 
344
393
  Now that you've enriched the activities you can render them in a view.
345
394
  For convenience we include a basic view:
@@ -47,7 +47,7 @@ module StreamRails
47
47
  end
48
48
 
49
49
  def activity_object
50
- fail NotImplementedError, "Activity models must define `#activity_object` - missing on `#{self.class}`"
50
+ raise NotImplementedError, "Activity models must define `#activity_object` - missing on `#{self.class}`"
51
51
  end
52
52
 
53
53
  def activity_target
@@ -70,8 +70,7 @@ module StreamRails
70
70
  StreamRails.create_reference(activity_target) if activity_target
71
71
  end
72
72
 
73
- def activity_notify
74
- end
73
+ def activity_notify; end
75
74
 
76
75
  def activity_extra_data
77
76
  {}
@@ -95,7 +94,7 @@ module StreamRails
95
94
  time: activity_time
96
95
  }
97
96
  activity[:to] = activity_notify.map(&:id) unless activity_notify.nil?
98
- activity.merge(activity_extra_data)
97
+ activity.merge(activity_extra_data) if activity_extra_data != nil
99
98
  end
100
99
  end
101
100
  end
@@ -15,7 +15,7 @@ module StreamRails
15
15
  end
16
16
 
17
17
  def enriched?
18
- @failed_to_enrich.keys.length == 0
18
+ @failed_to_enrich.keys.length.zero?
19
19
  end
20
20
 
21
21
  def not_enriched_fields
@@ -28,10 +28,16 @@ module StreamRails
28
28
  end
29
29
 
30
30
  class Enrich
31
+ attr_reader :fields
32
+
31
33
  def initialize(fields = nil)
32
34
  @fields = fields || [:actor, :object, :target]
33
35
  end
34
36
 
37
+ def add_fields(new_fields)
38
+ new_fields.each { |i| @fields << i }
39
+ end
40
+
35
41
  def model_field?(field_value)
36
42
  return false unless field_value.respond_to?('split')
37
43
  bits = field_value.split(':')
@@ -68,7 +74,7 @@ module StreamRails
68
74
  model_refs = Hash.new { |h, k| h[k] = {} }
69
75
  activities.each do |activity|
70
76
  activity.select { |k, _v| @fields.include? k.to_sym }.each do |_field, value|
71
- next unless self.model_field?(value)
77
+ next unless model_field?(value)
72
78
  model, id = value.split(':')
73
79
  model_refs[model][id] = 0
74
80
  end
@@ -83,7 +89,7 @@ module StreamRails
83
89
  def inject_objects(activities, objects)
84
90
  create_activity_results(activities).each do |activity|
85
91
  activity.select { |k, _v| @fields.include? k.to_sym }.each do |field, value|
86
- next unless self.model_field?(value)
92
+ next unless model_field?(value)
87
93
  model, id = value.split(':')
88
94
  activity[field] = objects[model][id] || value
89
95
  activity.track_not_enriched_field(field, value) if objects[model][id].nil?
@@ -12,7 +12,7 @@ module StreamRails
12
12
  end
13
13
  end
14
14
  else
15
- fail 'Your ORM is not supported'
15
+ raise 'Your ORM is not supported'
16
16
  end
17
17
  end
18
18
 
@@ -38,7 +38,7 @@ module StreamRails
38
38
  end
39
39
  end
40
40
  else
41
- fail 'Your ORM is not supported'
41
+ raise 'Your ORM is not supported'
42
42
  end
43
43
  end
44
44
 
@@ -1,3 +1,3 @@
1
1
  module StreamRails
2
- VERSION = '2.5.0'
2
+ VERSION = '2.5.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stream_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 2.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tommaso Barbugli
8
+ - Ian Douglas
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2016-09-14 00:00:00.000000000 Z
12
+ date: 2016-12-27 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: actionpack
@@ -28,16 +29,16 @@ dependencies:
28
29
  name: railties
29
30
  requirement: !ruby/object:Gem::Requirement
30
31
  requirements:
31
- - - ">="
32
+ - - "~>"
32
33
  - !ruby/object:Gem::Version
33
- version: 3.0.0
34
+ version: '3.0'
34
35
  type: :runtime
35
36
  prerelease: false
36
37
  version_requirements: !ruby/object:Gem::Requirement
37
38
  requirements:
38
- - - ">="
39
+ - - "~>"
39
40
  - !ruby/object:Gem::Version
40
- version: 3.0.0
41
+ version: '3.0'
41
42
  - !ruby/object:Gem::Dependency
42
43
  name: stream-ruby
43
44
  requirement: !ruby/object:Gem::Requirement
@@ -70,44 +71,44 @@ dependencies:
70
71
  name: rake
71
72
  requirement: !ruby/object:Gem::Requirement
72
73
  requirements:
73
- - - ">="
74
+ - - "~>"
74
75
  - !ruby/object:Gem::Version
75
- version: '0'
76
+ version: 10.5.0
76
77
  type: :development
77
78
  prerelease: false
78
79
  version_requirements: !ruby/object:Gem::Requirement
79
80
  requirements:
80
- - - ">="
81
+ - - "~>"
81
82
  - !ruby/object:Gem::Version
82
- version: '0'
83
+ version: 10.5.0
83
84
  - !ruby/object:Gem::Dependency
84
85
  name: fakeweb
85
86
  requirement: !ruby/object:Gem::Requirement
86
87
  requirements:
87
- - - ">="
88
+ - - "~>"
88
89
  - !ruby/object:Gem::Version
89
- version: '0'
90
+ version: 1.3.0
90
91
  type: :development
91
92
  prerelease: false
92
93
  version_requirements: !ruby/object:Gem::Requirement
93
94
  requirements:
94
- - - ">="
95
+ - - "~>"
95
96
  - !ruby/object:Gem::Version
96
- version: '0'
97
+ version: 1.3.0
97
98
  - !ruby/object:Gem::Dependency
98
99
  name: sqlite3
99
100
  requirement: !ruby/object:Gem::Requirement
100
101
  requirements:
101
- - - ">="
102
+ - - "~>"
102
103
  - !ruby/object:Gem::Version
103
- version: '0'
104
+ version: 1.3.12
104
105
  type: :development
105
106
  prerelease: false
106
107
  version_requirements: !ruby/object:Gem::Requirement
107
108
  requirements:
108
- - - ">="
109
+ - - "~>"
109
110
  - !ruby/object:Gem::Version
110
- version: '0'
111
+ version: 1.3.12
111
112
  - !ruby/object:Gem::Dependency
112
113
  name: rspec
113
114
  requirement: !ruby/object:Gem::Requirement
@@ -151,7 +152,7 @@ dependencies:
151
152
  - !ruby/object:Gem::Version
152
153
  version: '4.29'
153
154
  description:
154
- email: tommaso@getstream.io
155
+ email: support@getstream.io
155
156
  executables: []
156
157
  extensions: []
157
158
  extra_rdoc_files:
@@ -191,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
191
192
  version: '0'
192
193
  requirements: []
193
194
  rubyforge_project:
194
- rubygems_version: 2.5.1
195
+ rubygems_version: 2.6.6
195
196
  signing_key:
196
197
  specification_version: 4
197
198
  summary: A gem that provides a client interface for getstream.io