tekeya 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/tekeya/entity.rb +24 -13
- data/lib/tekeya/feed/activity/item.rb +16 -7
- data/lib/tekeya/version.rb +1 -1
- data/spec/fabricators/company_fabricator.rb +3 -0
- data/spec/rails_app/app/active_record/company.rb +3 -0
- data/spec/rails_app/app/mongoid/company.rb +7 -0
- data/spec/rails_app/db/migrate/103_create_companies.rb +9 -0
- data/spec/tekeya/activity_spec.rb +2 -2
- data/spec/tekeya/entity_spec.rb +4 -0
- metadata +18 -10
data/lib/tekeya/entity.rb
CHANGED
@@ -16,11 +16,14 @@ module Tekeya
|
|
16
16
|
has_many :activities, as: :entity, class_name: "::Tekeya::Activity", dependent: :destroy do
|
17
17
|
# Returns activities dating up to 10 days in the past
|
18
18
|
def recent
|
19
|
-
unless ::Tekeya::Configuration.instance.feed_storage_orm.to_sym == :mongoid
|
19
|
+
c = unless ::Tekeya::Configuration.instance.feed_storage_orm.to_sym == :mongoid
|
20
20
|
where("created_at > ?", 10.days.ago).order('created_at DESC')
|
21
21
|
else
|
22
22
|
criteria.where(:created_at.gte => 10.days.ago).desc('created_at')
|
23
23
|
end
|
24
|
+
|
25
|
+
c = yield c if block_given?
|
26
|
+
c
|
24
27
|
end
|
25
28
|
|
26
29
|
# Any method missing invoked on activities is considered a new activity
|
@@ -301,13 +304,13 @@ module Tekeya
|
|
301
304
|
# Returns the entity's recent activities
|
302
305
|
#
|
303
306
|
# @return [Array] the list of recent activities by this entity
|
304
|
-
def profile_feed
|
307
|
+
def profile_feed(&blck)
|
305
308
|
acts = []
|
306
309
|
pkey = self.profile_feed_key
|
307
310
|
recent_activities_count = ::Tekeya.redis.zcard(pkey)
|
308
311
|
|
309
312
|
# Check if the cache is not empty
|
310
|
-
if recent_activities_count > 0
|
313
|
+
if recent_activities_count > 0 && !block_given?
|
311
314
|
# Retrieve the aggregate keys from redis
|
312
315
|
acts_keys = ::Tekeya.redis.zrevrange(pkey, 0, -1)
|
313
316
|
# Retrieve the aggregates
|
@@ -322,7 +325,7 @@ module Tekeya
|
|
322
325
|
end
|
323
326
|
else
|
324
327
|
# Retrieve the activities from the DB
|
325
|
-
db_recent_activities = self.activities.recent
|
328
|
+
db_recent_activities = self.activities.recent(&blck)
|
326
329
|
db_recent_activities.each do |activity|
|
327
330
|
acts << ::Tekeya::Feed::Activity::Item.from_db(activity, activity.author)
|
328
331
|
end
|
@@ -334,23 +337,29 @@ module Tekeya
|
|
334
337
|
# Returns the entity's feed
|
335
338
|
#
|
336
339
|
# @return [Array] the list of activities for the entities tracked by this entity
|
337
|
-
def feed
|
340
|
+
def feed(&blck)
|
338
341
|
acts = []
|
339
342
|
fkey = self.feed_key
|
340
343
|
recent_activities_count = ::Tekeya.redis.zcard(fkey)
|
341
344
|
|
342
345
|
# Check if the cache is not empty
|
343
|
-
if recent_activities_count > 0
|
346
|
+
if recent_activities_count > 0 && !block_given?
|
344
347
|
# Retrieve the aggregate keys from redis
|
345
348
|
acts_keys = ::Tekeya.redis.zrevrange(fkey, 0, -1)
|
346
349
|
# Retrieve the aggregates
|
347
350
|
acts_keys.each do |act_key|
|
348
|
-
|
351
|
+
# Make `from_redis` only hit the db if author != entity
|
352
|
+
key_components = act_key.split(':')
|
353
|
+
actor = if key_components[4] == self.class.to_s && key_components[5] == self.entity_primary_key
|
354
|
+
self
|
355
|
+
end
|
356
|
+
|
357
|
+
acts << ::Tekeya::Feed::Activity::Item.from_redis(act_key, actor)
|
349
358
|
end
|
350
359
|
else
|
351
360
|
# Retrieve the activities from the DB
|
352
361
|
(self.tracking + [self]).each do |tracker|
|
353
|
-
db_recent_activities = tracker.activities.recent
|
362
|
+
db_recent_activities = tracker.activities.recent(&blck)
|
354
363
|
db_recent_activities.each do |activity|
|
355
364
|
acts << ::Tekeya::Feed::Activity::Item.from_db(activity, tracker)
|
356
365
|
end
|
@@ -416,17 +425,19 @@ module Tekeya
|
|
416
425
|
# Retrieves rebat relations
|
417
426
|
def tekeya_relations_of(from, relation_type, entity_type, reverse = false)
|
418
427
|
result_entity_class = entity_type.safe_constantize if entity_type
|
419
|
-
unless reverse
|
428
|
+
relations = unless reverse
|
420
429
|
::Tekeya.relations.where(from.send(from.class.entity_primary_key), from.class.name, nil, entity_type, relation_type).entries.map do |entry|
|
421
|
-
result_entity_class
|
422
|
-
|
430
|
+
entity_class = result_entity_class || entry.toEntityType.safe_constantize
|
431
|
+
entity_class.where(:"#{entity_class.entity_primary_key}" => entry.toEntityId).first
|
423
432
|
end
|
424
433
|
else
|
425
434
|
::Tekeya.relations.where(nil, entity_type, from.send(from.class.entity_primary_key), from.class.name, relation_type).entries.map do |entry|
|
426
|
-
result_entity_class
|
427
|
-
|
435
|
+
entity_class = result_entity_class || entry.fromEntityType.safe_constantize
|
436
|
+
entity_class.where(:"#{entity_class.entity_primary_key}" => entry.fromEntityId).first
|
428
437
|
end
|
429
438
|
end
|
439
|
+
|
440
|
+
relations.compact
|
430
441
|
end
|
431
442
|
|
432
443
|
# @private
|
@@ -2,13 +2,14 @@ module Tekeya
|
|
2
2
|
module Feed
|
3
3
|
module Activity
|
4
4
|
class Item
|
5
|
-
attr_reader :activity_id, :activity_type, :attachments, :actor, :timestamp
|
5
|
+
attr_reader :activity_id, :activity_type, :attachments, :actor, :author, :timestamp
|
6
6
|
|
7
|
-
def initialize(activity_id, activity_type, attachments, actor, timestamp)
|
7
|
+
def initialize(activity_id, activity_type, attachments, actor, author, timestamp)
|
8
8
|
@activity_id = activity_id
|
9
9
|
@activity_type = activity_type
|
10
10
|
@attachments = attachments
|
11
11
|
@actor = actor
|
12
|
+
@author = author
|
12
13
|
@timestamp = timestamp
|
13
14
|
end
|
14
15
|
|
@@ -25,8 +26,15 @@ module Tekeya
|
|
25
26
|
act_time = Time.at(key_components[7].to_i)
|
26
27
|
|
27
28
|
if act_actor.nil?
|
28
|
-
actor_class = key_components[
|
29
|
-
act_actor = actor_class.where(:"#{actor_class.entity_primary_key}" => key_components[
|
29
|
+
actor_class = key_components[2].safe_constantize
|
30
|
+
act_actor = actor_class.where(:"#{actor_class.entity_primary_key}" => key_components[3]).first
|
31
|
+
end
|
32
|
+
|
33
|
+
act_author = unless key_components[2] == key_components[4] && key_components[3] == key_components[5]
|
34
|
+
author_class = key_components[4].safe_constantize
|
35
|
+
author_class.where(:"#{actor_class.entity_primary_key}" => key_components[5]).first
|
36
|
+
else
|
37
|
+
act_actor
|
30
38
|
end
|
31
39
|
|
32
40
|
act_attachments = ::Tekeya.redis.smembers(key).map{|act|
|
@@ -35,7 +43,7 @@ module Tekeya
|
|
35
43
|
att['attachable_type'].safe_constantize.find att['attachable_id']
|
36
44
|
}
|
37
45
|
|
38
|
-
return self.new(act_id, act_type, act_attachments, act_actor, act_time)
|
46
|
+
return self.new(act_id, act_type, act_attachments, act_actor, act_author, act_time)
|
39
47
|
end
|
40
48
|
|
41
49
|
# Builds a feed item a DB activity
|
@@ -47,10 +55,11 @@ module Tekeya
|
|
47
55
|
act_id = activity.id.to_s
|
48
56
|
act_type = activity.activity_type.to_sym
|
49
57
|
act_time = activity.created_at
|
50
|
-
act_actor ||= activity.
|
58
|
+
act_actor ||= activity.entity
|
59
|
+
act_author = activity.author
|
51
60
|
act_attachments = activity.attachments.map(&:attachable)
|
52
61
|
|
53
|
-
return self.new(act_id, act_type, act_attachments, act_actor, act_time)
|
62
|
+
return self.new(act_id, act_type, act_attachments, act_actor, act_author, act_time)
|
54
63
|
end
|
55
64
|
end
|
56
65
|
end
|
data/lib/tekeya/version.rb
CHANGED
@@ -15,9 +15,9 @@ describe "Tekeya" do
|
|
15
15
|
@act2 = @user.activities.liked Fabricate(:status)
|
16
16
|
@act3 = @user.activities.shared Fabricate(:status)
|
17
17
|
|
18
|
-
# Created
|
18
|
+
# Created before the grouping interval
|
19
19
|
@act4 = @user.activities.new activity_type: :liked, attachments: [Fabricate.build(:attachment)]
|
20
|
-
@act4.stub(:current_time_from_proper_timezone => @act1.created_at
|
20
|
+
@act4.stub(:current_time_from_proper_timezone => @act1.created_at - 20.minutes)
|
21
21
|
@act4.save!
|
22
22
|
|
23
23
|
# Manually not grouped
|
data/spec/tekeya/entity_spec.rb
CHANGED
@@ -102,11 +102,14 @@ describe "Tekeya" do
|
|
102
102
|
describe "retrieval" do
|
103
103
|
before :each do
|
104
104
|
@user3 = Fabricate(:user)
|
105
|
+
@company = Fabricate(:company)
|
106
|
+
|
105
107
|
@user.track(@user2)
|
106
108
|
@user.block(@user3)
|
107
109
|
@user.join(@group)
|
108
110
|
@user2.join(@group)
|
109
111
|
@user3.join(@group)
|
112
|
+
@company.track(@user2)
|
110
113
|
end
|
111
114
|
|
112
115
|
it "should return tracked entities" do
|
@@ -115,6 +118,7 @@ describe "Tekeya" do
|
|
115
118
|
|
116
119
|
it "should return trackers" do
|
117
120
|
@user2.trackers.include?(@user).should == true
|
121
|
+
@user2.trackers.include?(@company).should == true
|
118
122
|
end
|
119
123
|
|
120
124
|
it "should return blocked entities" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tekeya
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-04-14 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: redis
|
17
|
-
requirement: &
|
17
|
+
requirement: &70225140539400 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: 3.0.1
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70225140539400
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: rebat
|
28
|
-
requirement: &
|
28
|
+
requirement: &70225140538900 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: 0.1.4
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70225140538900
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: resque
|
39
|
-
requirement: &
|
39
|
+
requirement: &70225140538420 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: 1.23.0
|
45
45
|
type: :runtime
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70225140538420
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: railties
|
50
|
-
requirement: &
|
50
|
+
requirement: &70225140537940 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ~>
|
@@ -55,7 +55,7 @@ dependencies:
|
|
55
55
|
version: '3.1'
|
56
56
|
type: :runtime
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *70225140537940
|
59
59
|
description: a social engine for Rails applications based on Redis and RebatDB
|
60
60
|
email:
|
61
61
|
- omar.mekky@mashsolvents.com
|
@@ -107,17 +107,20 @@ files:
|
|
107
107
|
- lib/tekeya/railtie.rb
|
108
108
|
- lib/tekeya/version.rb
|
109
109
|
- spec/fabricators/attachment_fabricator.rb
|
110
|
+
- spec/fabricators/company_fabricator.rb
|
110
111
|
- spec/fabricators/group_fabricator.rb
|
111
112
|
- spec/fabricators/status_fabricator.rb
|
112
113
|
- spec/fabricators/user_fabricator.rb
|
113
114
|
- spec/orm/active_record.rb
|
114
115
|
- spec/orm/mongoid.rb
|
115
116
|
- spec/rails_app/Rakefile
|
117
|
+
- spec/rails_app/app/active_record/company.rb
|
116
118
|
- spec/rails_app/app/active_record/group.rb
|
117
119
|
- spec/rails_app/app/active_record/status.rb
|
118
120
|
- spec/rails_app/app/active_record/user.rb
|
119
121
|
- spec/rails_app/app/controllers/application_controller.rb
|
120
122
|
- spec/rails_app/app/helpers/application_helper.rb
|
123
|
+
- spec/rails_app/app/mongoid/company.rb
|
121
124
|
- spec/rails_app/app/mongoid/group.rb
|
122
125
|
- spec/rails_app/app/mongoid/status.rb
|
123
126
|
- spec/rails_app/app/mongoid/user.rb
|
@@ -140,6 +143,7 @@ files:
|
|
140
143
|
- spec/rails_app/db/migrate/100_create_users.rb
|
141
144
|
- spec/rails_app/db/migrate/101_create_groups.rb
|
142
145
|
- spec/rails_app/db/migrate/102_create_statuses.rb
|
146
|
+
- spec/rails_app/db/migrate/103_create_companies.rb
|
143
147
|
- spec/rails_app/db/seeds.rb
|
144
148
|
- spec/rails_app/public/404.html
|
145
149
|
- spec/rails_app/public/422.html
|
@@ -181,17 +185,20 @@ specification_version: 3
|
|
181
185
|
summary: a social engine for Rails applications based on Redis and RebatDB.
|
182
186
|
test_files:
|
183
187
|
- spec/fabricators/attachment_fabricator.rb
|
188
|
+
- spec/fabricators/company_fabricator.rb
|
184
189
|
- spec/fabricators/group_fabricator.rb
|
185
190
|
- spec/fabricators/status_fabricator.rb
|
186
191
|
- spec/fabricators/user_fabricator.rb
|
187
192
|
- spec/orm/active_record.rb
|
188
193
|
- spec/orm/mongoid.rb
|
189
194
|
- spec/rails_app/Rakefile
|
195
|
+
- spec/rails_app/app/active_record/company.rb
|
190
196
|
- spec/rails_app/app/active_record/group.rb
|
191
197
|
- spec/rails_app/app/active_record/status.rb
|
192
198
|
- spec/rails_app/app/active_record/user.rb
|
193
199
|
- spec/rails_app/app/controllers/application_controller.rb
|
194
200
|
- spec/rails_app/app/helpers/application_helper.rb
|
201
|
+
- spec/rails_app/app/mongoid/company.rb
|
195
202
|
- spec/rails_app/app/mongoid/group.rb
|
196
203
|
- spec/rails_app/app/mongoid/status.rb
|
197
204
|
- spec/rails_app/app/mongoid/user.rb
|
@@ -214,6 +221,7 @@ test_files:
|
|
214
221
|
- spec/rails_app/db/migrate/100_create_users.rb
|
215
222
|
- spec/rails_app/db/migrate/101_create_groups.rb
|
216
223
|
- spec/rails_app/db/migrate/102_create_statuses.rb
|
224
|
+
- spec/rails_app/db/migrate/103_create_companies.rb
|
217
225
|
- spec/rails_app/db/seeds.rb
|
218
226
|
- spec/rails_app/public/404.html
|
219
227
|
- spec/rails_app/public/422.html
|