socialization 1.2.1 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/specs.yml +35 -0
- data/.gitignore +1 -0
- data/.ruby-version +1 -1
- data/Appraisals +4 -20
- data/CHANGELOG.md +17 -0
- data/README.md +5 -22
- data/lib/socialization/stores/active_record/follow.rb +6 -16
- data/lib/socialization/stores/active_record/like.rb +6 -16
- data/lib/socialization/stores/active_record/mention.rb +6 -16
- 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
- data/lib/socialization.rb +1 -1
- data/socialization.gemspec +1 -2
- data/spec/actors/liker_spec.rb +3 -4
- data/spec/actors/mentioner_spec.rb +3 -4
- data/spec/spec_helper.rb +1 -0
- metadata +24 -79
- data/.travis.yml +0 -7
- data/demo/.gitignore +0 -15
- data/demo/Gemfile +0 -35
- data/demo/README.rdoc +0 -261
- data/demo/Rakefile +0 -7
- data/demo/app/assets/images/rails.png +0 -0
- data/demo/app/assets/javascripts/application.js +0 -15
- data/demo/app/assets/stylesheets/application.css +0 -13
- data/demo/app/controllers/application_controller.rb +0 -3
- data/demo/app/helpers/application_helper.rb +0 -2
- data/demo/app/mailers/.gitkeep +0 -0
- data/demo/app/models/.gitkeep +0 -0
- data/demo/app/models/celebrity.rb +0 -4
- data/demo/app/models/comment.rb +0 -5
- data/demo/app/models/follow.rb +0 -3
- data/demo/app/models/like.rb +0 -2
- data/demo/app/models/mention.rb +0 -2
- data/demo/app/models/movie.rb +0 -3
- data/demo/app/models/user.rb +0 -7
- data/demo/app/views/layouts/application.html.erb +0 -14
- data/demo/config/application.rb +0 -59
- data/demo/config/boot.rb +0 -6
- data/demo/config/database.yml +0 -25
- data/demo/config/environment.rb +0 -5
- data/demo/config/environments/development.rb +0 -37
- data/demo/config/environments/production.rb +0 -67
- data/demo/config/environments/test.rb +0 -37
- data/demo/config/initializers/backtrace_silencers.rb +0 -7
- data/demo/config/initializers/inflections.rb +0 -15
- data/demo/config/initializers/mime_types.rb +0 -5
- data/demo/config/initializers/secret_token.rb +0 -7
- data/demo/config/initializers/session_store.rb +0 -8
- data/demo/config/initializers/wrap_parameters.rb +0 -14
- data/demo/config/locales/en.yml +0 -5
- data/demo/config/routes.rb +0 -58
- data/demo/config.ru +0 -4
- data/demo/db/migrate/20120115051222_create_users.rb +0 -9
- data/demo/db/migrate/20120115051234_create_movies.rb +0 -9
- data/demo/db/migrate/20120115051255_create_celebrities.rb +0 -9
- data/demo/db/migrate/20120115054646_create_follows.rb +0 -14
- data/demo/db/migrate/20120115054647_create_likes.rb +0 -14
- data/demo/db/migrate/20120221200644_create_mentions.rb +0 -14
- data/demo/db/migrate/20120221202703_create_comments.rb +0 -9
- data/demo/db/schema.rb +0 -72
- data/demo/db/seeds.rb +0 -17
- data/demo/lib/assets/.gitkeep +0 -0
- data/demo/lib/tasks/.gitkeep +0 -0
- data/demo/public/404.html +0 -26
- data/demo/public/422.html +0 -26
- data/demo/public/500.html +0 -25
- data/demo/public/favicon.ico +0 -0
- data/demo/public/index.html +0 -204
- data/demo/public/robots.txt +0 -5
- data/demo/script/rails +0 -6
- data/demo/test/fixtures/.gitkeep +0 -0
- data/demo/test/fixtures/celebrities.yml +0 -7
- data/demo/test/fixtures/movies.yml +0 -7
- data/demo/test/fixtures/users.yml +0 -7
- data/demo/test/functional/.gitkeep +0 -0
- data/demo/test/integration/.gitkeep +0 -0
- data/demo/test/performance/browsing_test.rb +0 -12
- data/demo/test/test_helper.rb +0 -13
- data/demo/test/unit/.gitkeep +0 -0
- data/demo/test/unit/celebrity_test.rb +0 -7
- data/demo/test/unit/movie_test.rb +0 -7
- data/demo/test/unit/user_test.rb +0 -7
- data/demo/vendor/assets/javascripts/.gitkeep +0 -0
- data/demo/vendor/assets/stylesheets/.gitkeep +0 -0
- data/demo/vendor/plugins/.gitkeep +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22d8b3559cb4bc0d9138ea45753f7fab5f06ba44f1b583da221612c9c3a596c6
|
4
|
+
data.tar.gz: 14465566e6b73fd7f4fe8d815f09987e3f4468d7e98a250fdb74e1f0a1b63f08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.7.2
|
data/Appraisals
CHANGED
@@ -1,23 +1,7 @@
|
|
1
|
-
appraise "
|
2
|
-
gem "activerecord", "~>
|
1
|
+
appraise "activerecord614" do
|
2
|
+
gem "activerecord", "~> 6.1.4"
|
3
3
|
end
|
4
4
|
|
5
|
-
appraise "
|
6
|
-
gem "activerecord", "~>
|
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
|
-
|
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
|
27
|
+
### Legacy Rails Support
|
29
28
|
|
30
|
-
This gem requires Rails
|
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-
|
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.
|
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.
|
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.
|
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
|
-
|
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.
|
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
|
-
|
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.
|
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.
|
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.
|
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
|
-
|
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.
|
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
|
-
|
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.
|
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.
|
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.
|
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
|
-
|
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.
|
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
|
-
|
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,
|
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)
|
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)
|
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
|
data/lib/socialization.rb
CHANGED
data/socialization.gemspec
CHANGED
@@ -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
|
data/spec/actors/liker_spec.rb
CHANGED
@@ -47,15 +47,14 @@ describe Socialization::Liker do
|
|
47
47
|
end
|
48
48
|
|
49
49
|
it "unlikes when likeing" do
|
50
|
-
|
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
|
-
|
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
|
|