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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d61ca6903bc5188ade02e94d8b2b8bdc974d9153dfd96729a4742036b5020a4f
4
- data.tar.gz: e773f8ef9a1eaea46e81920ab79ff6f0432a45790e3d200f79f03f182a26ec7d
3
+ metadata.gz: 6bb2c1347bb2975c9a229366e60e2f1552f95e28b2c4ac27ab7e48edd963caaf
4
+ data.tar.gz: a2a9d47da210368463afa8c56cc943548f4765f350c762ede7f84c9e942e2c01
5
5
  SHA512:
6
- metadata.gz: e934d16150b977dee6ed8051674eb48c1d7d88607552a2cf95bb06a02c196cd760138219f3b6cf41ee18bbc318009b00d9c3646c0f3216718938ac9bb63c03aa
7
- data.tar.gz: 9c1747627c2fabccc5e12d644d5dec60897c6a4a0fc2fd93b6bc8144d2736c1da29e78b9c3d8d84cf2a32690201a7a665b0964769ef5ba78bfa2791b59a513b2
6
+ metadata.gz: b903ff8c62263cf0f4f9f4a748b77c508f0d81065584a867a7c21aea2990d38873d9eb08321ceb782e733d979f985a07c0be708a8a2beac33372da4d2ce4bad0
7
+ data.tar.gz: a7ac541cbf6de510aa841a622086d869406050a21dc41580c7e5ab74a0127eb18e01c6e55ba47f004ecfcc703850bb7f723ff9292fa72a9b969b5f7124e25c28
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.3 (April 17, 2019)
4
+
5
+ * Rename "victim" methods to "subject" internally. Thanks to @jdugarte for the suggestion.
6
+
3
7
  ## 1.2.2 (April 17, 2019)
4
8
 
5
9
  * Drop support for some old Ruby versions
@@ -10,7 +10,7 @@
10
10
  stores/redis/base.rb
11
11
  stores/redis/**/*.rb
12
12
  actors/**/*.rb
13
- victims/**/*.rb
13
+ subjects/**/*.rb
14
14
  helpers/**/*.rb
15
15
  config/**/*.rb
16
16
  ).each do |path|
@@ -2,9 +2,9 @@ module Socialization
2
2
  module Stores
3
3
  module Mixins
4
4
  module Base
5
- def touch_dependents(actor, victim)
5
+ def touch_dependents(actor, subject)
6
6
  actor.touch if touch_actor?(actor)
7
- victim.touch if touch_victim?(victim)
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 touch_victim?(victim)
16
- return false unless victim.respond_to?(:touch)
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(victim, klass, options = {})
7
+ def actors(subject, klass, options = {})
8
8
  if options[:pluck]
9
- Socialization.redis.smembers(generate_forward_key(victim)).inject([]) do |result, element|
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(victim, klass, options).to_a
14
+ actors_relation(subject, klass, options).to_a
15
15
  end
16
16
  end
17
17
 
18
- def actors_relation(victim, klass, options = {})
19
- ids = actors(victim, klass, :pluck => :id)
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 victims_relation(actor, klass, options = {})
24
- ids = victims(actor, klass, :pluck => :id)
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 victims(actor, klass, options = {})
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
- victims_relation(actor, klass, options).to_a
36
+ subjects_relation(actor, klass, options).to_a
36
37
  end
37
38
  end
39
+ alias victims subjects
38
40
 
39
- def relation!(actor, victim, options = {})
40
- unless options[:skip_check] || relation?(actor, victim)
41
- Socialization.redis.sadd generate_forward_key(victim), generate_redis_value(actor)
42
- Socialization.redis.sadd generate_backward_key(actor), generate_redis_value(victim)
43
- call_after_create_hooks(actor, victim)
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, victim, options = {})
51
- if options[:skip_check] || relation?(actor, victim)
52
- Socialization.redis.srem generate_forward_key(victim), generate_redis_value(actor)
53
- Socialization.redis.srem generate_backward_key(actor), generate_redis_value(victim)
54
- call_after_destroy_hooks(actor, victim)
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, victim)
62
- Socialization.redis.sismember generate_forward_key(victim), generate_redis_value(actor)
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(victim)
66
- forward_key = generate_forward_key(victim)
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(victim)
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 remove_victim_relations(actor)
77
+ def remove_subject_relations(actor)
76
78
  backward_key = generate_backward_key(actor)
77
- victims = Socialization.redis.smembers backward_key
79
+ subjects = Socialization.redis.smembers backward_key
78
80
  Socialization.redis.del backward_key
79
- victims.each do |victim|
80
- Socialization.redis.srem generate_forward_key(victim), generate_redis_value(actor)
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(victim)
102
+ def generate_forward_key(subject)
100
103
  keys = key_type_to_type_names(self)
101
- if victim.is_a?(String)
102
- "#{keys[0].pluralize.capitalize}:#{victim}"
104
+ if subject.is_a?(String)
105
+ "#{keys[0].pluralize.capitalize}:#{subject}"
103
106
  else
104
- "#{keys[0].pluralize.capitalize}:#{victim.class}:#{victim.id}"
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!; 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, :victims_relation; public :followables_relation
15
- alias_method :followables, :victims; public :followables
16
- alias_method :remove_followers, :remove_actor_relations; public :remove_followers
17
- alias_method :remove_followables, :remove_victim_relations; public :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!; 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, :victims_relation; public :likeables_relation
15
- alias_method :likeables, :victims; public :likeables
16
- alias_method :remove_likers, :remove_actor_relations; public :remove_likers
17
- alias_method :remove_likeables, :remove_victim_relations; public :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, :victims_relation; public :mentionables_relation
15
- alias_method :mentionables, :victims; public :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, :remove_victim_relations; public :remove_mentionables
17
+ alias_method :remove_mentionables, :remove_subject_relations; public :remove_mentionables
18
18
  end
19
19
 
20
20
  end
@@ -1,3 +1,3 @@
1
1
  module Socialization
2
- VERSION = "1.2.2"
2
+ VERSION = "1.2.3"
3
3
  end
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.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