followability 1.0.0 → 1.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 74981f3a807c733f78c36f78ebec08e18f9469415ca5fe500ba902a244f2490a
4
- data.tar.gz: 49109e4a45692f73f206b3847610d0c725a8837b7a561d5f99b5641e6e53e89c
3
+ metadata.gz: 5381804ee6dcba9d0a7fcd76d2a560e9b6ff371aa3b2c4212cb394f8abbf4468
4
+ data.tar.gz: 4aae8e97665f8b10f1a1ee31d9b244d1a63fed320d7e9777249c907c215e3d5f
5
5
  SHA512:
6
- metadata.gz: cd0716f68c519a24544e47d9d88c21a1eb006485c99b92419cd166dcd847c9876e2b3fa3df968afd061e8ce3a13ff481893e8dd09f331aad47e045a505b5ab4b
7
- data.tar.gz: 29b0bda4d267f4d8b34a1a5f438e64eb5135e775af9cb283815570e417fd35eb322e7e1b612062b3a2972fc58904b70c41bfe353d9f66cd12758f24277170fe2
6
+ metadata.gz: db1fab64911111ec2ef69ca06f4b173f4bd0daf4e49085fcbaae2674c6b1efac9e549ffe492ab2205eee0bc413200c09910094fa4819b914cb92a0bfbe1a6fa5
7
+ data.tar.gz: fb8e8e23c3b63158ba16e7981d85de9ee0382ee530d3b0de2194feb125e6d6ba5ed209c1c5caa12476814701e50038bd906c1b70fb19b2cc1c808d0b526636d2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- followability (0.1.0)
4
+ followability (1.0.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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?
@@ -80,27 +81,20 @@ Avaiable methods:
80
81
  @foo.mutual_following_with?(@bar)
81
82
  # => false
82
83
 
83
- @foo.errors.full_messages
84
- # => [...]
85
-
86
84
  @bar.following?(@foo)
87
85
  # => false
88
-
89
- @foo.errors.full_messages
90
- # => [...]
91
-
92
86
  ```
93
87
 
94
88
  ### Blocking actions
95
89
  Avaiable methods:
96
- - block_to
97
- - unblock_to
90
+ - block
91
+ - unblock
98
92
  - blocked?
99
93
  - blocked_by?
100
94
 
101
95
  ### Usage
102
96
  ```ruby
103
- @foo.block_to(@bar)
97
+ @foo.block(@bar)
104
98
  # => true
105
99
 
106
100
  @foo.blocked?(@bar)
@@ -109,7 +103,7 @@ Avaiable methods:
109
103
  @bar.blocked_by?(@foo)
110
104
  # => true
111
105
 
112
- @foo.unblock_to(@bar)
106
+ @foo.unblock(@bar)
113
107
  # => true
114
108
  ```
115
109
 
@@ -178,6 +172,8 @@ Available methods:
178
172
  - followable_blocked_by_someone
179
173
  - followable_unblocked_by_me
180
174
  - followable_unblocked_by_someone
175
+ - unfollow_by_me
176
+ - unfollow_by_someone
181
177
  - followability_triggered
182
178
 
183
179
  ### Usage
@@ -188,6 +184,7 @@ class User < ActiveRecord::Base
188
184
  def follow_request_sent_to_me(record)
189
185
  Notifications::FollowRequestSentToMeJob.perform_later(from_id: record.id)
190
186
  end
187
+
191
188
  def follow_request_sent_to_someone(record); end
192
189
  def follow_request_accepted_by_me(record); end
193
190
  def follow_request_accepted_by_someone(record); end
@@ -199,6 +196,12 @@ class User < ActiveRecord::Base
199
196
  def followable_blocked_by_someone(record); end
200
197
  def followable_unblocked_by_me(record); end
201
198
  def followable_unblocked_by_someone(record); end
199
+ def unfollow_by_me(record); end
200
+
201
+ def unfollow_by_someone(record)
202
+ Followability::RemoveFollowedUser(user_id: record.id)
203
+ end
204
+
202
205
  def followability_triggered(record, callback_name); end
203
206
  end
204
207
  ```
@@ -206,19 +209,21 @@ end
206
209
  ## I18n
207
210
  ```yml
208
211
  ---
209
- ---
210
212
  en:
211
213
  followability:
212
214
  errors:
213
215
  block:
214
- unblock_to:
216
+ unblock:
215
217
  myself: 'You can not run this action for yourself'
216
- block_to:
218
+ block:
217
219
  myself: 'You can not run this action for yourself'
218
220
  blocked_by: 'You can not block to who blocked to you'
219
221
  already_blocked: '%{klass} already blocked'
220
222
  not_blocked_for_blocking: 'You can not unblock to %{klass} because was not blocked'
221
223
  follow:
224
+ unfollow:
225
+ myself: 'You can not run this action for yourself'
226
+ empty_relation: 'You can not unfollow to %{klass} because was not followed'
222
227
  decline_follow_request_of:
223
228
  myself: 'You can not run this action for yourself'
224
229
  empty_relation: 'You can not decline follow request of %{klass} because was not sent'
@@ -3,14 +3,17 @@ en:
3
3
  followability:
4
4
  errors:
5
5
  block:
6
- unblock_to:
6
+ unblock:
7
7
  myself: 'You can not run this action for yourself'
8
- block_to:
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'
@@ -6,15 +6,15 @@ module Followability
6
6
  module Block
7
7
  I18N_SCOPE = 'followability.errors.block'
8
8
 
9
- def block_to(record)
9
+ def block(record)
10
10
  if myself?(record)
11
- errors.add(:base, I18n.t('block_to.myself', scope: I18N_SCOPE, klass: record.class))
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('block_to.blocked_by', scope: I18N_SCOPE, klass: record.class))
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 unblock_to(record)
43
+ def unblock(record)
44
44
  if myself?(record)
45
- errors.add(:base, I18n.t('unblock_to.myself', scope: I18N_SCOPE, klass: record.class))
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: :unfollow_by_me)
55
+ run_callback(record, affected: self, callback: :unfollow_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))
@@ -16,6 +16,8 @@ module Followability
16
16
  followable_blocked_by_someone
17
17
  followable_unblocked_by_me
18
18
  followable_unblocked_by_someone
19
+ unfollow_by_me
20
+ unfollow_by_someone
19
21
  followability_triggered
20
22
  ].freeze
21
23
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Followability
4
- VERSION = '1.0.0'
4
+ VERSION = '1.1.0'
5
5
  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.0.0
4
+ version: 1.1.0
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-15 00:00:00.000000000 Z
11
+ date: 2022-10-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Implements the social network followable functionality for your Active
14
14
  Record models.