followability 1.0.0 → 1.1.1

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: 74981f3a807c733f78c36f78ebec08e18f9469415ca5fe500ba902a244f2490a
4
- data.tar.gz: 49109e4a45692f73f206b3847610d0c725a8837b7a561d5f99b5641e6e53e89c
3
+ metadata.gz: 46c4bbdfdbae3003841116e1a71dae9c1573350a800c2bf4138031673cebe1a6
4
+ data.tar.gz: bc915022b767b6f945108d65442fefb42c72680b63e81649cff1dc315f6da0d8
5
5
  SHA512:
6
- metadata.gz: cd0716f68c519a24544e47d9d88c21a1eb006485c99b92419cd166dcd847c9876e2b3fa3df968afd061e8ce3a13ff481893e8dd09f331aad47e045a505b5ab4b
7
- data.tar.gz: 29b0bda4d267f4d8b34a1a5f438e64eb5135e775af9cb283815570e417fd35eb322e7e1b612062b3a2972fc58904b70c41bfe353d9f66cd12758f24277170fe2
6
+ metadata.gz: 3606b82feba15a46ba17284800f9a750279d1429fcbec0a679fa530f9ffbe97c4b8f11020ca572a977a82cc16fd2652e99694d5ee03ca28d5a7391545a7f8cbd
7
+ data.tar.gz: ea8d95ad732334a1576a44966c03da676e0966bf6ba79b9eba28394d63e2068c01392c88e8a056ce89cfd24cbaa8014d73100a520c555e1724b2567cd887af14
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.1.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?
@@ -71,36 +72,35 @@ Avaiable methods:
71
72
  @bar.errors.full_messages
72
73
  # => [...]
73
74
 
74
- @foo.remove_follow_request_for(@bar)
75
+ @bar.unfollow(@foo)
75
76
  # => false
76
77
 
77
- @foo.errors.full_messages
78
+ @bar.errors.full_messages
78
79
  # => [...]
79
80
 
80
- @foo.mutual_following_with?(@bar)
81
+ @foo.remove_follow_request_for(@bar)
81
82
  # => false
82
83
 
83
84
  @foo.errors.full_messages
84
85
  # => [...]
85
86
 
86
- @bar.following?(@foo)
87
+ @foo.mutual_following_with?(@bar)
87
88
  # => false
88
89
 
89
- @foo.errors.full_messages
90
- # => [...]
91
-
90
+ @bar.following?(@foo)
91
+ # => false
92
92
  ```
93
93
 
94
94
  ### Blocking actions
95
95
  Avaiable methods:
96
- - block_to
97
- - unblock_to
96
+ - block
97
+ - unblock
98
98
  - blocked?
99
99
  - blocked_by?
100
100
 
101
101
  ### Usage
102
102
  ```ruby
103
- @foo.block_to(@bar)
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.unblock_to(@bar)
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
- unblock_to:
226
+ unblock:
215
227
  myself: 'You can not run this action for yourself'
216
- block_to:
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
+ ![Friend Request And Followers - Followability Gem | Ruby On Rails 7 Tutorial](docs/youtube-video.jpeg)
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.
@@ -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'
Binary file
@@ -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: :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))
@@ -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
+ unfollowed_by_me
20
+ unfollowed_by_someone
19
21
  followability_triggered
20
22
  ].freeze
21
23
 
@@ -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
@@ -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.1'
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.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-15 00:00:00.000000000 Z
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