followability 1.0.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +34 -14
- data/config/locales/en.yml +5 -2
- data/docs/youtube-video.jpeg +0 -0
- data/lib/followability/followable/actions/block.rb +5 -5
- data/lib/followability/followable/actions/follow.rb +29 -0
- data/lib/followability/followable/callbacks.rb +2 -0
- data/lib/followability/followable.rb +9 -2
- data/lib/followability/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 46c4bbdfdbae3003841116e1a71dae9c1573350a800c2bf4138031673cebe1a6
|
|
4
|
+
data.tar.gz: bc915022b767b6f945108d65442fefb42c72680b63e81649cff1dc315f6da0d8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3606b82feba15a46ba17284800f9a750279d1429fcbec0a679fa530f9ffbe97c4b8f11020ca572a977a82cc16fd2652e99694d5ee03ca28d5a7391545a7f8cbd
|
|
7
|
+
data.tar.gz: ea8d95ad732334a1576a44966c03da676e0966bf6ba79b9eba28394d63e2068c01392c88e8a056ce89cfd24cbaa8014d73100a520c555e1724b2567cd887af14
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -47,6 +47,7 @@ Avaiable methods:
|
|
|
47
47
|
- decline_follow_request_of
|
|
48
48
|
- remove_follow_request_for
|
|
49
49
|
- send_follow_request_to
|
|
50
|
+
- unfollow
|
|
50
51
|
- following?
|
|
51
52
|
- mutual_following_with?
|
|
52
53
|
- sent_follow_request_to?
|
|
@@ -71,36 +72,35 @@ Avaiable methods:
|
|
|
71
72
|
@bar.errors.full_messages
|
|
72
73
|
# => [...]
|
|
73
74
|
|
|
74
|
-
@
|
|
75
|
+
@bar.unfollow(@foo)
|
|
75
76
|
# => false
|
|
76
77
|
|
|
77
|
-
@
|
|
78
|
+
@bar.errors.full_messages
|
|
78
79
|
# => [...]
|
|
79
80
|
|
|
80
|
-
@foo.
|
|
81
|
+
@foo.remove_follow_request_for(@bar)
|
|
81
82
|
# => false
|
|
82
83
|
|
|
83
84
|
@foo.errors.full_messages
|
|
84
85
|
# => [...]
|
|
85
86
|
|
|
86
|
-
@
|
|
87
|
+
@foo.mutual_following_with?(@bar)
|
|
87
88
|
# => false
|
|
88
89
|
|
|
89
|
-
@foo
|
|
90
|
-
# =>
|
|
91
|
-
|
|
90
|
+
@bar.following?(@foo)
|
|
91
|
+
# => false
|
|
92
92
|
```
|
|
93
93
|
|
|
94
94
|
### Blocking actions
|
|
95
95
|
Avaiable methods:
|
|
96
|
-
-
|
|
97
|
-
-
|
|
96
|
+
- block
|
|
97
|
+
- unblock
|
|
98
98
|
- blocked?
|
|
99
99
|
- blocked_by?
|
|
100
100
|
|
|
101
101
|
### Usage
|
|
102
102
|
```ruby
|
|
103
|
-
@foo.
|
|
103
|
+
@foo.block(@bar)
|
|
104
104
|
# => true
|
|
105
105
|
|
|
106
106
|
@foo.blocked?(@bar)
|
|
@@ -109,7 +109,7 @@ Avaiable methods:
|
|
|
109
109
|
@bar.blocked_by?(@foo)
|
|
110
110
|
# => true
|
|
111
111
|
|
|
112
|
-
@foo.
|
|
112
|
+
@foo.unblock(@bar)
|
|
113
113
|
# => true
|
|
114
114
|
```
|
|
115
115
|
|
|
@@ -139,6 +139,7 @@ Avaiable methods:
|
|
|
139
139
|
- followers
|
|
140
140
|
- following
|
|
141
141
|
- blocks
|
|
142
|
+
- blockers
|
|
142
143
|
|
|
143
144
|
### Usage
|
|
144
145
|
```ruby
|
|
@@ -162,6 +163,9 @@ Avaiable methods:
|
|
|
162
163
|
|
|
163
164
|
@foo.blocks
|
|
164
165
|
# => [#<User ...>]
|
|
166
|
+
|
|
167
|
+
@foo.blockers
|
|
168
|
+
# => [#<User ...>]
|
|
165
169
|
```
|
|
166
170
|
|
|
167
171
|
### Callback Methods
|
|
@@ -178,6 +182,8 @@ Available methods:
|
|
|
178
182
|
- followable_blocked_by_someone
|
|
179
183
|
- followable_unblocked_by_me
|
|
180
184
|
- followable_unblocked_by_someone
|
|
185
|
+
- unfollowed_by_me
|
|
186
|
+
- unfollowed_by_someone
|
|
181
187
|
- followability_triggered
|
|
182
188
|
|
|
183
189
|
### Usage
|
|
@@ -188,6 +194,7 @@ class User < ActiveRecord::Base
|
|
|
188
194
|
def follow_request_sent_to_me(record)
|
|
189
195
|
Notifications::FollowRequestSentToMeJob.perform_later(from_id: record.id)
|
|
190
196
|
end
|
|
197
|
+
|
|
191
198
|
def follow_request_sent_to_someone(record); end
|
|
192
199
|
def follow_request_accepted_by_me(record); end
|
|
193
200
|
def follow_request_accepted_by_someone(record); end
|
|
@@ -199,6 +206,12 @@ class User < ActiveRecord::Base
|
|
|
199
206
|
def followable_blocked_by_someone(record); end
|
|
200
207
|
def followable_unblocked_by_me(record); end
|
|
201
208
|
def followable_unblocked_by_someone(record); end
|
|
209
|
+
def unfollowed_by_me(record); end
|
|
210
|
+
|
|
211
|
+
def unfollowed_by_someone(record)
|
|
212
|
+
Followability::RemoveFollowedUserJob.perform_later(user_id: record.id)
|
|
213
|
+
end
|
|
214
|
+
|
|
202
215
|
def followability_triggered(record, callback_name); end
|
|
203
216
|
end
|
|
204
217
|
```
|
|
@@ -206,19 +219,21 @@ end
|
|
|
206
219
|
## I18n
|
|
207
220
|
```yml
|
|
208
221
|
---
|
|
209
|
-
---
|
|
210
222
|
en:
|
|
211
223
|
followability:
|
|
212
224
|
errors:
|
|
213
225
|
block:
|
|
214
|
-
|
|
226
|
+
unblock:
|
|
215
227
|
myself: 'You can not run this action for yourself'
|
|
216
|
-
|
|
228
|
+
block:
|
|
217
229
|
myself: 'You can not run this action for yourself'
|
|
218
230
|
blocked_by: 'You can not block to who blocked to you'
|
|
219
231
|
already_blocked: '%{klass} already blocked'
|
|
220
232
|
not_blocked_for_blocking: 'You can not unblock to %{klass} because was not blocked'
|
|
221
233
|
follow:
|
|
234
|
+
unfollow:
|
|
235
|
+
myself: 'You can not run this action for yourself'
|
|
236
|
+
empty_relation: 'You can not unfollow to %{klass} because was not followed'
|
|
222
237
|
decline_follow_request_of:
|
|
223
238
|
myself: 'You can not run this action for yourself'
|
|
224
239
|
empty_relation: 'You can not decline follow request of %{klass} because was not sent'
|
|
@@ -236,6 +251,11 @@ en:
|
|
|
236
251
|
blocked: 'You can not send follow request to blocked %{klass}'
|
|
237
252
|
```
|
|
238
253
|
|
|
254
|
+
## Mentioned Youtube Video
|
|
255
|
+

|
|
256
|
+
|
|
257
|
+
You can watch [@Deanout](https://github.com/Deanout)'s [Friend Request And Followers - Followability Gem | Ruby On Rails 7 Tutorial Video](https://www.youtube.com/watch?v=UVa1QPaITQM) on Youtube.
|
|
258
|
+
|
|
239
259
|
## Development
|
|
240
260
|
|
|
241
261
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/config/locales/en.yml
CHANGED
|
@@ -3,14 +3,17 @@ en:
|
|
|
3
3
|
followability:
|
|
4
4
|
errors:
|
|
5
5
|
block:
|
|
6
|
-
|
|
6
|
+
unblock:
|
|
7
7
|
myself: 'You can not run this action for yourself'
|
|
8
|
-
|
|
8
|
+
block:
|
|
9
9
|
myself: 'You can not run this action for yourself'
|
|
10
10
|
blocked_by: 'You can not block to who blocked to you'
|
|
11
11
|
already_blocked: '%{klass} already blocked'
|
|
12
12
|
not_blocked_for_blocking: 'You can not unblock to %{klass} because was not blocked'
|
|
13
13
|
follow:
|
|
14
|
+
unfollow:
|
|
15
|
+
myself: 'You can not run this action for yourself'
|
|
16
|
+
empty_relation: 'You can not unfollow to %{klass} because was not followed'
|
|
14
17
|
decline_follow_request_of:
|
|
15
18
|
myself: 'You can not run this action for yourself'
|
|
16
19
|
empty_relation: 'You can not decline follow request of %{klass} because was not sent'
|
|
Binary file
|
|
@@ -6,15 +6,15 @@ module Followability
|
|
|
6
6
|
module Block
|
|
7
7
|
I18N_SCOPE = 'followability.errors.block'
|
|
8
8
|
|
|
9
|
-
def
|
|
9
|
+
def block(record)
|
|
10
10
|
if myself?(record)
|
|
11
|
-
errors.add(:base, I18n.t('
|
|
11
|
+
errors.add(:base, I18n.t('block.myself', scope: I18N_SCOPE, klass: record.class))
|
|
12
12
|
|
|
13
13
|
return false
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
if blocked_by?(record)
|
|
17
|
-
errors.add(:base, I18n.t('
|
|
17
|
+
errors.add(:base, I18n.t('block.blocked_by', scope: I18N_SCOPE, klass: record.class))
|
|
18
18
|
|
|
19
19
|
return false
|
|
20
20
|
end
|
|
@@ -40,9 +40,9 @@ module Followability
|
|
|
40
40
|
end
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
-
def
|
|
43
|
+
def unblock(record)
|
|
44
44
|
if myself?(record)
|
|
45
|
-
errors.add(:base, I18n.t('
|
|
45
|
+
errors.add(:base, I18n.t('unblock.myself', scope: I18N_SCOPE, klass: record.class))
|
|
46
46
|
|
|
47
47
|
return false
|
|
48
48
|
end
|
|
@@ -33,6 +33,35 @@ module Followability
|
|
|
33
33
|
end
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
+
def unfollow(record)
|
|
37
|
+
if myself?(record)
|
|
38
|
+
errors.add(:base, I18n.t('unfollow.myself', scope: I18N_SCOPE, klass: record.class))
|
|
39
|
+
|
|
40
|
+
return false
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
unless following?(record)
|
|
44
|
+
errors.add(:base, I18n.t('unfollow.not_following', scope: I18N_SCOPE, klass: record.class))
|
|
45
|
+
|
|
46
|
+
return false
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
relation = followerable_relationships.find_by(followable_id: record.id,
|
|
50
|
+
followable_type: record.class.name,
|
|
51
|
+
status: Followable::Relationship.statuses[:following])
|
|
52
|
+
|
|
53
|
+
if relation.destroy
|
|
54
|
+
run_callback(self, affected: record, callback: :unfollowed_by_me)
|
|
55
|
+
run_callback(record, affected: self, callback: :unfollowed_by_someone)
|
|
56
|
+
|
|
57
|
+
true
|
|
58
|
+
else
|
|
59
|
+
errors.add(:base, relation.errors.full_messages)
|
|
60
|
+
|
|
61
|
+
false
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
36
65
|
def accept_follow_request_of(record)
|
|
37
66
|
if myself?(record)
|
|
38
67
|
errors.add(:base, I18n.t('accept_follow_request_of.myself', scope: I18N_SCOPE, klass: record.class))
|
|
@@ -6,7 +6,7 @@ module Followability
|
|
|
6
6
|
false
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
# rubocop:disable Metrics/MethodLength
|
|
9
|
+
# rubocop:disable Metrics/MethodLength, Metrics/BlockLength
|
|
10
10
|
def followability
|
|
11
11
|
class_eval do
|
|
12
12
|
def self.followability?
|
|
@@ -43,6 +43,13 @@ module Followability
|
|
|
43
43
|
source: :followable,
|
|
44
44
|
class_name: name,
|
|
45
45
|
source_type: name
|
|
46
|
+
|
|
47
|
+
has_many :blockers,
|
|
48
|
+
-> { Followability::Relationship.blocked },
|
|
49
|
+
through: :followable_relationships,
|
|
50
|
+
source: :followerable,
|
|
51
|
+
class_name: name,
|
|
52
|
+
source_type: name
|
|
46
53
|
end
|
|
47
54
|
|
|
48
55
|
include Followability::Followable::Associations
|
|
@@ -51,6 +58,6 @@ module Followability
|
|
|
51
58
|
include Followability::Followable::Actions::Follow
|
|
52
59
|
include Followability::Followable::Actions::Block
|
|
53
60
|
end
|
|
54
|
-
# rubocop:enable Metrics/MethodLength
|
|
61
|
+
# rubocop:enable Metrics/MethodLength, Metrics/BlockLength
|
|
55
62
|
end
|
|
56
63
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: followability
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- nejdetkadir
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2022-10-
|
|
11
|
+
date: 2022-10-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Implements the social network followable functionality for your Active
|
|
14
14
|
Record models.
|
|
@@ -28,6 +28,7 @@ files:
|
|
|
28
28
|
- README.md
|
|
29
29
|
- Rakefile
|
|
30
30
|
- config/locales/en.yml
|
|
31
|
+
- docs/youtube-video.jpeg
|
|
31
32
|
- followability.gemspec
|
|
32
33
|
- lib/followability.rb
|
|
33
34
|
- lib/followability/followable.rb
|