socialization 1.2.2 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/socialization.rb +1 -1
- data/lib/socialization/stores/mixins/base.rb +5 -4
- data/lib/socialization/stores/redis/base.rb +35 -32
- data/lib/socialization/stores/redis/follow.rb +9 -9
- data/lib/socialization/stores/redis/like.rb +9 -9
- data/lib/socialization/stores/redis/mention.rb +3 -3
- data/lib/socialization/{victims → subjects}/followable.rb +0 -0
- data/lib/socialization/{victims → subjects}/likeable.rb +0 -0
- data/lib/socialization/{victims → subjects}/mentionable.rb +0 -0
- data/lib/socialization/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bb2c1347bb2975c9a229366e60e2f1552f95e28b2c4ac27ab7e48edd963caaf
|
4
|
+
data.tar.gz: a2a9d47da210368463afa8c56cc943548f4765f350c762ede7f84c9e942e2c01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b903ff8c62263cf0f4f9f4a748b77c508f0d81065584a867a7c21aea2990d38873d9eb08321ceb782e733d979f985a07c0be708a8a2beac33372da4d2ce4bad0
|
7
|
+
data.tar.gz: a7ac541cbf6de510aa841a622086d869406050a21dc41580c7e5ab74a0127eb18e01c6e55ba47f004ecfcc703850bb7f723ff9292fa72a9b969b5f7124e25c28
|
data/CHANGELOG.md
CHANGED
data/lib/socialization.rb
CHANGED
@@ -2,9 +2,9 @@ module Socialization
|
|
2
2
|
module Stores
|
3
3
|
module Mixins
|
4
4
|
module Base
|
5
|
-
def touch_dependents(actor,
|
5
|
+
def touch_dependents(actor, subject)
|
6
6
|
actor.touch if touch_actor?(actor)
|
7
|
-
|
7
|
+
subject.touch if touch_subject?(subject)
|
8
8
|
end
|
9
9
|
|
10
10
|
def touch_actor?(actor)
|
@@ -12,10 +12,11 @@ module Socialization
|
|
12
12
|
touch == :all || touch.to_s =~ /er$/i
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
return false unless
|
15
|
+
def touch_subject?(subject)
|
16
|
+
return false unless subject.respond_to?(:touch)
|
17
17
|
touch == :all || touch.to_s =~ /able$/i
|
18
18
|
end
|
19
|
+
alias touch_victim? touch_subject?
|
19
20
|
end
|
20
21
|
end
|
21
22
|
end
|
@@ -4,83 +4,86 @@ module Socialization
|
|
4
4
|
|
5
5
|
class << self
|
6
6
|
protected
|
7
|
-
def actors(
|
7
|
+
def actors(subject, klass, options = {})
|
8
8
|
if options[:pluck]
|
9
|
-
Socialization.redis.smembers(generate_forward_key(
|
9
|
+
Socialization.redis.smembers(generate_forward_key(subject)).inject([]) do |result, element|
|
10
10
|
result << element.match(/\:(\d+)$/)[1] if element.match(/^#{klass}\:/)
|
11
11
|
result
|
12
12
|
end
|
13
13
|
else
|
14
|
-
actors_relation(
|
14
|
+
actors_relation(subject, klass, options).to_a
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
def actors_relation(
|
19
|
-
ids = actors(
|
18
|
+
def actors_relation(subject, klass, options = {})
|
19
|
+
ids = actors(subject, klass, :pluck => :id)
|
20
20
|
klass.where("#{klass.table_name}.id IN (?)", ids)
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
24
|
-
ids =
|
23
|
+
def subjects_relation(actor, klass, options = {})
|
24
|
+
ids = subjects(actor, klass, :pluck => :id)
|
25
25
|
klass.where("#{klass.table_name}.id IN (?)", ids)
|
26
26
|
end
|
27
|
+
alias victims_relation subjects_relation
|
27
28
|
|
28
|
-
def
|
29
|
+
def subjects(actor, klass, options = {})
|
29
30
|
if options[:pluck]
|
30
31
|
Socialization.redis.smembers(generate_backward_key(actor)).inject([]) do |result, element|
|
31
32
|
result << element.match(/\:(\d+)$/)[1] if element.match(/^#{klass}\:/)
|
32
33
|
result
|
33
34
|
end
|
34
35
|
else
|
35
|
-
|
36
|
+
subjects_relation(actor, klass, options).to_a
|
36
37
|
end
|
37
38
|
end
|
39
|
+
alias victims subjects
|
38
40
|
|
39
|
-
def relation!(actor,
|
40
|
-
unless options[:skip_check] || relation?(actor,
|
41
|
-
Socialization.redis.sadd generate_forward_key(
|
42
|
-
Socialization.redis.sadd generate_backward_key(actor), generate_redis_value(
|
43
|
-
call_after_create_hooks(actor,
|
41
|
+
def relation!(actor, subject, options = {})
|
42
|
+
unless options[:skip_check] || relation?(actor, subject)
|
43
|
+
Socialization.redis.sadd generate_forward_key(subject), generate_redis_value(actor)
|
44
|
+
Socialization.redis.sadd generate_backward_key(actor), generate_redis_value(subject)
|
45
|
+
call_after_create_hooks(actor, subject)
|
44
46
|
true
|
45
47
|
else
|
46
48
|
false
|
47
49
|
end
|
48
50
|
end
|
49
51
|
|
50
|
-
def unrelation!(actor,
|
51
|
-
if options[:skip_check] || relation?(actor,
|
52
|
-
Socialization.redis.srem generate_forward_key(
|
53
|
-
Socialization.redis.srem generate_backward_key(actor), generate_redis_value(
|
54
|
-
call_after_destroy_hooks(actor,
|
52
|
+
def unrelation!(actor, subject, options = {})
|
53
|
+
if options[:skip_check] || relation?(actor, subject)
|
54
|
+
Socialization.redis.srem generate_forward_key(subject), generate_redis_value(actor)
|
55
|
+
Socialization.redis.srem generate_backward_key(actor), generate_redis_value(subject)
|
56
|
+
call_after_destroy_hooks(actor, subject)
|
55
57
|
true
|
56
58
|
else
|
57
59
|
false
|
58
60
|
end
|
59
61
|
end
|
60
62
|
|
61
|
-
def relation?(actor,
|
62
|
-
Socialization.redis.sismember generate_forward_key(
|
63
|
+
def relation?(actor, subject)
|
64
|
+
Socialization.redis.sismember generate_forward_key(subject), generate_redis_value(actor)
|
63
65
|
end
|
64
66
|
|
65
|
-
def remove_actor_relations(
|
66
|
-
forward_key = generate_forward_key(
|
67
|
+
def remove_actor_relations(subject)
|
68
|
+
forward_key = generate_forward_key(subject)
|
67
69
|
actors = Socialization.redis.smembers forward_key
|
68
70
|
Socialization.redis.del forward_key
|
69
71
|
actors.each do |actor|
|
70
|
-
Socialization.redis.srem generate_backward_key(actor), generate_redis_value(
|
72
|
+
Socialization.redis.srem generate_backward_key(actor), generate_redis_value(subject)
|
71
73
|
end
|
72
74
|
true
|
73
75
|
end
|
74
76
|
|
75
|
-
def
|
77
|
+
def remove_subject_relations(actor)
|
76
78
|
backward_key = generate_backward_key(actor)
|
77
|
-
|
79
|
+
subjects = Socialization.redis.smembers backward_key
|
78
80
|
Socialization.redis.del backward_key
|
79
|
-
|
80
|
-
Socialization.redis.srem generate_forward_key(
|
81
|
+
subjects.each do |subject|
|
82
|
+
Socialization.redis.srem generate_forward_key(subject), generate_redis_value(actor)
|
81
83
|
end
|
82
84
|
true
|
83
85
|
end
|
86
|
+
alias remove_victim_relations remove_subject_relations
|
84
87
|
|
85
88
|
|
86
89
|
private
|
@@ -96,12 +99,12 @@ module Socialization
|
|
96
99
|
end
|
97
100
|
end
|
98
101
|
|
99
|
-
def generate_forward_key(
|
102
|
+
def generate_forward_key(subject)
|
100
103
|
keys = key_type_to_type_names(self)
|
101
|
-
if
|
102
|
-
"#{keys[0].pluralize.capitalize}:#{
|
104
|
+
if subject.is_a?(String)
|
105
|
+
"#{keys[0].pluralize.capitalize}:#{subject}"
|
103
106
|
else
|
104
|
-
"#{keys[0].pluralize.capitalize}:#{
|
107
|
+
"#{keys[0].pluralize.capitalize}:#{subject.class}:#{subject.id}"
|
105
108
|
end
|
106
109
|
end
|
107
110
|
|
@@ -6,15 +6,15 @@ module Socialization
|
|
6
6
|
extend Socialization::RedisStores::Mixins::Base
|
7
7
|
|
8
8
|
class << self
|
9
|
-
alias_method :follow!, :relation!;
|
10
|
-
alias_method :unfollow!, :unrelation!;
|
11
|
-
alias_method :follows?, :relation?;
|
12
|
-
alias_method :followers_relation, :actors_relation;
|
13
|
-
alias_method :followers, :actors;
|
14
|
-
alias_method :followables_relation, :
|
15
|
-
alias_method :followables, :
|
16
|
-
alias_method :remove_followers, :remove_actor_relations;
|
17
|
-
alias_method :remove_followables, :
|
9
|
+
alias_method :follow!, :relation!; public :follow!
|
10
|
+
alias_method :unfollow!, :unrelation!; public :unfollow!
|
11
|
+
alias_method :follows?, :relation?; public :follows?
|
12
|
+
alias_method :followers_relation, :actors_relation; public :followers_relation
|
13
|
+
alias_method :followers, :actors; public :followers
|
14
|
+
alias_method :followables_relation, :subjects_relation; public :followables_relation
|
15
|
+
alias_method :followables, :subjects; public :followables
|
16
|
+
alias_method :remove_followers, :remove_actor_relations; public :remove_followers
|
17
|
+
alias_method :remove_followables, :remove_subject_relations; public :remove_followables
|
18
18
|
end
|
19
19
|
|
20
20
|
end
|
@@ -6,15 +6,15 @@ module Socialization
|
|
6
6
|
extend Socialization::RedisStores::Mixins::Base
|
7
7
|
|
8
8
|
class << self
|
9
|
-
alias_method :like!, :relation!;
|
10
|
-
alias_method :unlike!, :unrelation!;
|
11
|
-
alias_method :likes?, :relation?;
|
12
|
-
alias_method :likers_relation, :actors_relation;
|
13
|
-
alias_method :likers, :actors;
|
14
|
-
alias_method :likeables_relation, :
|
15
|
-
alias_method :likeables, :
|
16
|
-
alias_method :remove_likers, :remove_actor_relations;
|
17
|
-
alias_method :remove_likeables, :
|
9
|
+
alias_method :like!, :relation!; public :like!
|
10
|
+
alias_method :unlike!, :unrelation!; public :unlike!
|
11
|
+
alias_method :likes?, :relation?; public :likes?
|
12
|
+
alias_method :likers_relation, :actors_relation; public :likers_relation
|
13
|
+
alias_method :likers, :actors; public :likers
|
14
|
+
alias_method :likeables_relation, :subjects_relation; public :likeables_relation
|
15
|
+
alias_method :likeables, :subjects; public :likeables
|
16
|
+
alias_method :remove_likers, :remove_actor_relations; public :remove_likers
|
17
|
+
alias_method :remove_likeables, :remove_subject_relations; public :remove_likeables
|
18
18
|
end
|
19
19
|
|
20
20
|
end
|
@@ -11,10 +11,10 @@ module Socialization
|
|
11
11
|
alias_method :mentions?, :relation?; public :mentions?
|
12
12
|
alias_method :mentioners_relation, :actors_relation; public :mentioners_relation
|
13
13
|
alias_method :mentioners, :actors; public :mentioners
|
14
|
-
alias_method :mentionables_relation, :
|
15
|
-
alias_method :mentionables, :
|
14
|
+
alias_method :mentionables_relation, :subjects_relation; public :mentionables_relation
|
15
|
+
alias_method :mentionables, :subjects; public :mentionables
|
16
16
|
alias_method :remove_mentioners, :remove_actor_relations; public :remove_mentioners
|
17
|
-
alias_method :remove_mentionables, :
|
17
|
+
alias_method :remove_mentionables, :remove_subject_relations; public :remove_mentionables
|
18
18
|
end
|
19
19
|
|
20
20
|
end
|
File without changes
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: socialization
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carl Mercier
|
@@ -270,10 +270,10 @@ files:
|
|
270
270
|
- lib/socialization/stores/redis/like.rb
|
271
271
|
- lib/socialization/stores/redis/mention.rb
|
272
272
|
- lib/socialization/stores/redis/mixins/base.rb
|
273
|
+
- lib/socialization/subjects/followable.rb
|
274
|
+
- lib/socialization/subjects/likeable.rb
|
275
|
+
- lib/socialization/subjects/mentionable.rb
|
273
276
|
- lib/socialization/version.rb
|
274
|
-
- lib/socialization/victims/followable.rb
|
275
|
-
- lib/socialization/victims/likeable.rb
|
276
|
-
- lib/socialization/victims/mentionable.rb
|
277
277
|
- socialization.gemspec
|
278
278
|
- spec/actors/follower_spec.rb
|
279
279
|
- spec/actors/liker_spec.rb
|