socialization 1.2.1 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/specs.yml +35 -0
  3. data/.gitignore +1 -0
  4. data/.ruby-version +1 -1
  5. data/Appraisals +4 -20
  6. data/CHANGELOG.md +17 -0
  7. data/README.md +5 -22
  8. data/lib/socialization/stores/active_record/follow.rb +6 -16
  9. data/lib/socialization/stores/active_record/like.rb +6 -16
  10. data/lib/socialization/stores/active_record/mention.rb +6 -16
  11. data/lib/socialization/stores/mixins/base.rb +5 -4
  12. data/lib/socialization/stores/redis/base.rb +35 -32
  13. data/lib/socialization/stores/redis/follow.rb +9 -9
  14. data/lib/socialization/stores/redis/like.rb +9 -9
  15. data/lib/socialization/stores/redis/mention.rb +3 -3
  16. data/lib/socialization/{victims → subjects}/followable.rb +0 -0
  17. data/lib/socialization/{victims → subjects}/likeable.rb +0 -0
  18. data/lib/socialization/{victims → subjects}/mentionable.rb +0 -0
  19. data/lib/socialization/version.rb +1 -1
  20. data/lib/socialization.rb +1 -1
  21. data/socialization.gemspec +1 -2
  22. data/spec/actors/liker_spec.rb +3 -4
  23. data/spec/actors/mentioner_spec.rb +3 -4
  24. data/spec/spec_helper.rb +1 -0
  25. metadata +24 -79
  26. data/.travis.yml +0 -7
  27. data/demo/.gitignore +0 -15
  28. data/demo/Gemfile +0 -35
  29. data/demo/README.rdoc +0 -261
  30. data/demo/Rakefile +0 -7
  31. data/demo/app/assets/images/rails.png +0 -0
  32. data/demo/app/assets/javascripts/application.js +0 -15
  33. data/demo/app/assets/stylesheets/application.css +0 -13
  34. data/demo/app/controllers/application_controller.rb +0 -3
  35. data/demo/app/helpers/application_helper.rb +0 -2
  36. data/demo/app/mailers/.gitkeep +0 -0
  37. data/demo/app/models/.gitkeep +0 -0
  38. data/demo/app/models/celebrity.rb +0 -4
  39. data/demo/app/models/comment.rb +0 -5
  40. data/demo/app/models/follow.rb +0 -3
  41. data/demo/app/models/like.rb +0 -2
  42. data/demo/app/models/mention.rb +0 -2
  43. data/demo/app/models/movie.rb +0 -3
  44. data/demo/app/models/user.rb +0 -7
  45. data/demo/app/views/layouts/application.html.erb +0 -14
  46. data/demo/config/application.rb +0 -59
  47. data/demo/config/boot.rb +0 -6
  48. data/demo/config/database.yml +0 -25
  49. data/demo/config/environment.rb +0 -5
  50. data/demo/config/environments/development.rb +0 -37
  51. data/demo/config/environments/production.rb +0 -67
  52. data/demo/config/environments/test.rb +0 -37
  53. data/demo/config/initializers/backtrace_silencers.rb +0 -7
  54. data/demo/config/initializers/inflections.rb +0 -15
  55. data/demo/config/initializers/mime_types.rb +0 -5
  56. data/demo/config/initializers/secret_token.rb +0 -7
  57. data/demo/config/initializers/session_store.rb +0 -8
  58. data/demo/config/initializers/wrap_parameters.rb +0 -14
  59. data/demo/config/locales/en.yml +0 -5
  60. data/demo/config/routes.rb +0 -58
  61. data/demo/config.ru +0 -4
  62. data/demo/db/migrate/20120115051222_create_users.rb +0 -9
  63. data/demo/db/migrate/20120115051234_create_movies.rb +0 -9
  64. data/demo/db/migrate/20120115051255_create_celebrities.rb +0 -9
  65. data/demo/db/migrate/20120115054646_create_follows.rb +0 -14
  66. data/demo/db/migrate/20120115054647_create_likes.rb +0 -14
  67. data/demo/db/migrate/20120221200644_create_mentions.rb +0 -14
  68. data/demo/db/migrate/20120221202703_create_comments.rb +0 -9
  69. data/demo/db/schema.rb +0 -72
  70. data/demo/db/seeds.rb +0 -17
  71. data/demo/lib/assets/.gitkeep +0 -0
  72. data/demo/lib/tasks/.gitkeep +0 -0
  73. data/demo/public/404.html +0 -26
  74. data/demo/public/422.html +0 -26
  75. data/demo/public/500.html +0 -25
  76. data/demo/public/favicon.ico +0 -0
  77. data/demo/public/index.html +0 -204
  78. data/demo/public/robots.txt +0 -5
  79. data/demo/script/rails +0 -6
  80. data/demo/test/fixtures/.gitkeep +0 -0
  81. data/demo/test/fixtures/celebrities.yml +0 -7
  82. data/demo/test/fixtures/movies.yml +0 -7
  83. data/demo/test/fixtures/users.yml +0 -7
  84. data/demo/test/functional/.gitkeep +0 -0
  85. data/demo/test/integration/.gitkeep +0 -0
  86. data/demo/test/performance/browsing_test.rb +0 -12
  87. data/demo/test/test_helper.rb +0 -13
  88. data/demo/test/unit/.gitkeep +0 -0
  89. data/demo/test/unit/celebrity_test.rb +0 -7
  90. data/demo/test/unit/movie_test.rb +0 -7
  91. data/demo/test/unit/user_test.rb +0 -7
  92. data/demo/vendor/assets/javascripts/.gitkeep +0 -0
  93. data/demo/vendor/assets/stylesheets/.gitkeep +0 -0
  94. data/demo/vendor/plugins/.gitkeep +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d9501a281b94d2a30d020b90075669fb384b27ffcd6fa3499afd974af90b3634
4
- data.tar.gz: 183a8bc0b238e491f9d74822ad23f5777596ae0c8d536d2b0f28ce4eecd4e2b3
3
+ metadata.gz: 22d8b3559cb4bc0d9138ea45753f7fab5f06ba44f1b583da221612c9c3a596c6
4
+ data.tar.gz: 14465566e6b73fd7f4fe8d815f09987e3f4468d7e98a250fdb74e1f0a1b63f08
5
5
  SHA512:
6
- metadata.gz: b2ac47b149bd84943521fdafd9ab0351caa152ab3fa23ece63d769ef63babbaf1204c390d8c2cb6984f650ec2b2ecd13301245960e425b847fadf1840b160637
7
- data.tar.gz: 4bdc1e3181f17f44e34f0589e2687b48aff01da57ace6da88d499068f45a1124b963d30dce55496af58631284410d12fca9216aae70e83f3a376d32d7ba9dd09
6
+ metadata.gz: a3f1d7f31abb85b30943294d1b270eeca7f190ba4317e379c0f7fd4c8756b94d59a0204553d8462e781fdb6f331f448e3e565febe4c7099d32845fe9cc6c0741
7
+ data.tar.gz: 80ca7caf02ab9062200b1d521fcf7e8f463aa25097a988c2cea0f0f64f732f6943855043340c1b8a54dab80cc1c491be0ca95c125aff6707758483e6260ff41a
@@ -0,0 +1,35 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: "*"
13
+ pull_request:
14
+ branches: "*"
15
+
16
+ jobs:
17
+ rspec:
18
+ runs-on: ubuntu-latest
19
+ strategy:
20
+ matrix:
21
+ ruby-version: ['2.7', '3.0', '3.1']
22
+
23
+ steps:
24
+ - uses: actions/checkout@v2
25
+ - name: Set up Ruby
26
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
27
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
28
+ uses: ruby/setup-ruby@v1
29
+ with:
30
+ ruby-version: ${{ matrix.ruby-version }}
31
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
32
+ - name: Install dependencies
33
+ run: bundle exec appraisal install
34
+ - name: Run tests
35
+ run: bundle exec appraisal rspec
data/.gitignore CHANGED
@@ -11,3 +11,4 @@ doc
11
11
  .yardoc
12
12
  .rbenv-version
13
13
  gemfiles
14
+ .byebug_history
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.5.0
1
+ 2.7.2
data/Appraisals CHANGED
@@ -1,23 +1,7 @@
1
- appraise "activerecord30" do
2
- gem "activerecord", "~> 3.0.10"
1
+ appraise "activerecord614" do
2
+ gem "activerecord", "~> 6.1.4"
3
3
  end
4
4
 
5
- appraise "activerecord31" do
6
- gem "activerecord", "~> 3.1.1"
7
- end
8
-
9
- appraise "activerecord32" do
10
- gem "activerecord", "~> 3.2.1"
11
- end
12
-
13
- appraise "activerecord40" do
14
- gem "activerecord", "~> 4.0.13"
15
- end
16
-
17
- appraise "activerecord41" do
18
- gem "activerecord", "~> 4.1.12"
19
- end
20
-
21
- appraise "activerecord42" do
22
- gem "activerecord", "~> 4.2.3"
5
+ appraise "activerecord702" do
6
+ gem "activerecord", "~> 7.0.2"
23
7
  end
data/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.0.1 (February 18, 2022)
4
+
5
+ * Added support for namespaced models (thanks @marciotoze, @twrk, @mensfeld)
6
+
7
+ ## 2.0.0 (February 18, 2022)
8
+
9
+ * Dropped support for old Rails versions. Updated CI.
10
+ * BREAKING CHANGE (maybe): calling `followers`, `followables`, `likers`, `likeables`, `mentioners`, `mentionables` now returns `ActiveRecord::Relation` instead of an `Array`
11
+
12
+ ## 1.2.3 (April 17, 2019)
13
+
14
+ * Rename `victim` methods to `subject` internally. Thanks to @jdugarte for the suggestion.
15
+
16
+ ## 1.2.2 (April 17, 2019)
17
+
18
+ * Drop support for some old Ruby versions
19
+
3
20
  ## 1.2.1 (April 13, 2018)
4
21
 
5
22
  * You thought this project was dead huh!?
data/README.md CHANGED
@@ -8,12 +8,11 @@ The Like feature works just like a Facebook Like. For example, John likes Pulp F
8
8
 
9
9
  The Mention feature was written with Facebook mentions in mind. For example, John mentions Jane in a comment. Typically, Jane would be highlighted in the comment user interface and possibly notified that John mentioned her. This Facebook feature is occasionally called Tagging, although tagging is generally something [entirely different](http://en.wikipedia.org/wiki/Tag_(metadata).
10
10
 
11
- [![Build Status](https://secure.travis-ci.org/cmer/socialization.png?branch=master)](http://travis-ci.org/cmer/socialization)
11
+ ![Specs](https://github.com/cmer/socialization/actions/workflows/specs.yml/badge.svg)
12
+ [![Gem Version](https://badge.fury.io/rb/socialization.svg)](https://badge.fury.io/rb/socialization)
12
13
 
13
14
  ## Installation
14
15
 
15
- ### Rails 3/4
16
-
17
16
  Add the gem to the gemfile:
18
17
  `gem "socialization"`
19
18
 
@@ -25,9 +24,9 @@ Or if you want to use Redis as your data store:
25
24
 
26
25
  This will generate three migration files (when using ActiveRecord) and three models named Follow, Like and Mention. You may delete any of the Follow, Like or Mention models and migrations if you don't need that functionality in your application.
27
26
 
28
- ### Rails 2.3.x Support
27
+ ### Legacy Rails Support
29
28
 
30
- This gem requires Rails 3 or better. Sorry!
29
+ This gem requires Rails 6 or better. Sorry!
31
30
 
32
31
  ## Usage
33
32
 
@@ -264,22 +263,6 @@ You can find the compiled YARD documentation at http://rubydoc.info/github/cmer/
264
263
 
265
264
  ***
266
265
 
267
- ## Changelog
268
-
269
- Here it is: https://github.com/cmer/socialization/blob/master/CHANGELOG.md
270
-
271
- ## Demo App
272
-
273
- For your convenience, I have added a demo app in demo/demo_app. It does not have a web UI, but you can play with Socialization in the Rails console. It should also help you figure out hown to use Socialization in the Real World.
274
-
275
- To use the demo app:
276
-
277
- $ cd demo/demo_app
278
- $ bundle
279
- $ rake db:migrate
280
- $ rake db:seed
281
- $ rails console
282
-
283
266
 
284
267
  ## Note on Patches/Pull Requests
285
268
 
@@ -295,4 +278,4 @@ To use the demo app:
295
278
 
296
279
  ## Copyright
297
280
 
298
- Copyright (c) 2012-2015 Carl Mercier -- Released under the MIT license.
281
+ Copyright (c) 2012-2022 Carl Mercier -- Released under the MIT license.
@@ -9,12 +9,12 @@ module Socialization
9
9
  belongs_to :followable, :polymorphic => true
10
10
 
11
11
  scope :followed_by, lambda { |follower| where(
12
- :follower_type => follower.class.table_name.classify,
12
+ :follower_type => follower.class.name.classify,
13
13
  :follower_id => follower.id)
14
14
  }
15
15
 
16
16
  scope :following, lambda { |followable| where(
17
- :followable_type => followable.class.table_name.classify,
17
+ :followable_type => followable.class.name.classify,
18
18
  :followable_id => followable.id)
19
19
  }
20
20
 
@@ -54,7 +54,7 @@ module Socialization
54
54
  def followers_relation(followable, klass, opts = {})
55
55
  rel = klass.where(klass.primary_key =>
56
56
  self.select(:follower_id).
57
- where(:follower_type => klass.table_name.classify).
57
+ where(:follower_type => klass.name.classify).
58
58
  where(:followable_type => followable.class.to_s).
59
59
  where(:followable_id => followable.id)
60
60
  )
@@ -68,19 +68,14 @@ module Socialization
68
68
 
69
69
  # Returns all the followers of a certain type that are following followable
70
70
  def followers(followable, klass, opts = {})
71
- rel = followers_relation(followable, klass, opts)
72
- if rel.is_a?(ActiveRecord::Relation)
73
- rel.to_a
74
- else
75
- rel
76
- end
71
+ followers_relation(followable, klass, opts)
77
72
  end
78
73
 
79
74
  # Returns an ActiveRecord::Relation of all the followables of a certain type that are followed by follower
80
75
  def followables_relation(follower, klass, opts = {})
81
76
  rel = klass.where(klass.primary_key =>
82
77
  self.select(:followable_id).
83
- where(:followable_type => klass.table_name.classify).
78
+ where(:followable_type => klass.name.classify).
84
79
  where(:follower_type => follower.class.to_s).
85
80
  where(:follower_id => follower.id)
86
81
  )
@@ -94,12 +89,7 @@ module Socialization
94
89
 
95
90
  # Returns all the followables of a certain type that are followed by follower
96
91
  def followables(follower, klass, opts = {})
97
- rel = followables_relation(follower, klass, opts)
98
- if rel.is_a?(ActiveRecord::Relation)
99
- rel.to_a
100
- else
101
- rel
102
- end
92
+ followables_relation(follower, klass, opts)
103
93
  end
104
94
 
105
95
  # Remove all the followers for followable
@@ -9,12 +9,12 @@ module Socialization
9
9
  belongs_to :likeable, :polymorphic => true
10
10
 
11
11
  scope :liked_by, lambda { |liker| where(
12
- :liker_type => liker.class.table_name.classify,
12
+ :liker_type => liker.class.name.classify,
13
13
  :liker_id => liker.id)
14
14
  }
15
15
 
16
16
  scope :liking, lambda { |likeable| where(
17
- :likeable_type => likeable.class.table_name.classify,
17
+ :likeable_type => likeable.class.name.classify,
18
18
  :likeable_id => likeable.id)
19
19
  }
20
20
 
@@ -54,7 +54,7 @@ module Socialization
54
54
  def likers_relation(likeable, klass, opts = {})
55
55
  rel = klass.where(klass.primary_key =>
56
56
  self.select(:liker_id).
57
- where(:liker_type => klass.table_name.classify).
57
+ where(:liker_type => klass.name.classify).
58
58
  where(:likeable_type => likeable.class.to_s).
59
59
  where(:likeable_id => likeable.id)
60
60
  )
@@ -68,19 +68,14 @@ module Socialization
68
68
 
69
69
  # Returns all the likers of a certain type that are liking likeable
70
70
  def likers(likeable, klass, opts = {})
71
- rel = likers_relation(likeable, klass, opts)
72
- if rel.is_a?(ActiveRecord::Relation)
73
- rel.to_a
74
- else
75
- rel
76
- end
71
+ likers_relation(likeable, klass, opts)
77
72
  end
78
73
 
79
74
  # Returns an ActiveRecord::Relation of all the likeables of a certain type that are liked by liker
80
75
  def likeables_relation(liker, klass, opts = {})
81
76
  rel = klass.where(klass.primary_key =>
82
77
  self.select(:likeable_id).
83
- where(:likeable_type => klass.table_name.classify).
78
+ where(:likeable_type => klass.name.classify).
84
79
  where(:liker_type => liker.class.to_s).
85
80
  where(:liker_id => liker.id)
86
81
  )
@@ -94,12 +89,7 @@ module Socialization
94
89
 
95
90
  # Returns all the likeables of a certain type that are liked by liker
96
91
  def likeables(liker, klass, opts = {})
97
- rel = likeables_relation(liker, klass, opts)
98
- if rel.is_a?(ActiveRecord::Relation)
99
- rel.to_a
100
- else
101
- rel
102
- end
92
+ likeables_relation(liker, klass, opts)
103
93
  end
104
94
 
105
95
  # Remove all the likers for likeable
@@ -9,12 +9,12 @@ module Socialization
9
9
  belongs_to :mentionable, :polymorphic => true
10
10
 
11
11
  scope :mentioned_by, lambda { |mentioner| where(
12
- :mentioner_type => mentioner.class.table_name.classify,
12
+ :mentioner_type => mentioner.class.name.classify,
13
13
  :mentioner_id => mentioner.id)
14
14
  }
15
15
 
16
16
  scope :mentioning, lambda { |mentionable| where(
17
- :mentionable_type => mentionable.class.table_name.classify,
17
+ :mentionable_type => mentionable.class.name.classify,
18
18
  :mentionable_id => mentionable.id)
19
19
  }
20
20
 
@@ -54,7 +54,7 @@ module Socialization
54
54
  def mentioners_relation(mentionable, klass, opts = {})
55
55
  rel = klass.where(klass.primary_key =>
56
56
  self.select(:mentioner_id).
57
- where(:mentioner_type => klass.table_name.classify).
57
+ where(:mentioner_type => klass.name.classify).
58
58
  where(:mentionable_type => mentionable.class.to_s).
59
59
  where(:mentionable_id => mentionable.id)
60
60
  )
@@ -68,19 +68,14 @@ module Socialization
68
68
 
69
69
  # Returns all the mentioners of a certain type that are mentioning mentionable
70
70
  def mentioners(mentionable, klass, opts = {})
71
- rel = mentioners_relation(mentionable, klass, opts)
72
- if rel.is_a?(ActiveRecord::Relation)
73
- rel.to_a
74
- else
75
- rel
76
- end
71
+ mentioners_relation(mentionable, klass, opts)
77
72
  end
78
73
 
79
74
  # Returns an ActiveRecord::Relation of all the mentionables of a certain type that are mentioned by mentioner
80
75
  def mentionables_relation(mentioner, klass, opts = {})
81
76
  rel = klass.where(klass.primary_key =>
82
77
  self.select(:mentionable_id).
83
- where(:mentionable_type => klass.table_name.classify).
78
+ where(:mentionable_type => klass.name.classify).
84
79
  where(:mentioner_type => mentioner.class.to_s).
85
80
  where(:mentioner_id => mentioner.id)
86
81
  )
@@ -94,12 +89,7 @@ module Socialization
94
89
 
95
90
  # Returns all the mentionables of a certain type that are mentioned by mentioner
96
91
  def mentionables(mentioner, klass, opts = {})
97
- rel = mentionables_relation(mentioner, klass, opts)
98
- if rel.is_a?(ActiveRecord::Relation)
99
- rel.to_a
100
- else
101
- rel
102
- end
92
+ mentionables_relation(mentioner, klass, opts)
103
93
  end
104
94
 
105
95
  # Remove all the mentioners for mentionable
@@ -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)
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)
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
File without changes
@@ -1,3 +1,3 @@
1
1
  module Socialization
2
- VERSION = "1.2.1"
2
+ VERSION = "2.0.1"
3
3
  end
data/lib/socialization.rb CHANGED
@@ -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|
@@ -17,8 +17,6 @@ Gem::Specification.new do |s|
17
17
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
18
  s.require_paths = ["lib"]
19
19
 
20
- s.has_rdoc = false
21
-
22
20
  s.add_runtime_dependency "activerecord"
23
21
 
24
22
  s.add_development_dependency "appraisal"
@@ -30,4 +28,5 @@ Gem::Specification.new do |s|
30
28
  s.add_development_dependency "mock_redis"
31
29
  s.add_development_dependency "guard"
32
30
  s.add_development_dependency "guard-rspec"
31
+ s.add_development_dependency "byebug"
33
32
  end
@@ -47,15 +47,14 @@ describe Socialization::Liker do
47
47
  end
48
48
 
49
49
  it "unlikes when likeing" do
50
- expect(@liker).to receive(:likes?).with(@likeable).once.and_return(true)
51
- expect(@liker).to receive(:unlike!).with(@likeable).once
50
+ @liker.like!(@likeable)
52
51
  @liker.toggle_like!(@likeable)
52
+ expect(@liker.likes?(@likeable)).to be false
53
53
  end
54
54
 
55
55
  it "likes when not likeing" do
56
- expect(@liker).to receive(:likes?).with(@likeable).once.and_return(false)
57
- expect(@liker).to receive(:like!).with(@likeable).once
58
56
  @liker.toggle_like!(@likeable)
57
+ expect(@liker.likes?(@likeable)).to be true
59
58
  end
60
59
  end
61
60
 
@@ -47,15 +47,14 @@ describe Socialization::Mentioner do
47
47
  end
48
48
 
49
49
  it "unmentions when mentioning" do
50
- expect(@mentioner).to receive(:mentions?).with(@mentionable).once.and_return(true)
51
- expect(@mentioner).to receive(:unmention!).with(@mentionable).once
50
+ @mentioner.mention!(@mentionable)
52
51
  @mentioner.toggle_mention!(@mentionable)
52
+ expect(@mentioner.mentions?(@mentionable)).to eq false
53
53
  end
54
54
 
55
55
  it "mentions when not mentioning" do
56
- expect(@mentioner).to receive(:mentions?).with(@mentionable).once.and_return(false)
57
- expect(@mentioner).to receive(:mention!).with(@mentionable).once
58
56
  @mentioner.toggle_mention!(@mentionable)
57
+ expect(@mentioner.mentions?(@mentionable)).to eq true
59
58
  end
60
59
  end
61
60