has_friendship 1.1.5 → 1.1.6
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57947ab4c8d036df58994c27b253d0f301b7530da79c95a56d957dfe50ca2c94
|
4
|
+
data.tar.gz: 340377d9412274cc00905e2f469b2e1fff293a89c172b165bd1a92ae64ef7407
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34ca1faf29f2b1f70a88951f13b5beb9893948e140d312c798c179a7e1536518eec9a29ca7a76c17b926be9c1591e2baaf43e6750415483fe2e59906bd1c4535
|
7
|
+
data.tar.gz: c5a960c9adf8e360fd893971f650d653f7dda143f316771a5079d6ac9ce85d8bcb1dc2b011a9ff0cf4c5cb2481329f6d4905dc9f3f733cf15014c91fc67ae711
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module HasFriendship
|
2
2
|
module Friendable
|
3
|
-
|
4
3
|
def friendable?
|
5
4
|
false
|
6
5
|
end
|
@@ -39,6 +38,18 @@ module HasFriendship
|
|
39
38
|
end
|
40
39
|
|
41
40
|
module InstanceMethods
|
41
|
+
CALLBACK_METHOD_NAMES = %i(
|
42
|
+
on_friendship_created
|
43
|
+
on_friendship_accepted
|
44
|
+
on_friendship_blocked
|
45
|
+
on_friendship_destroyed
|
46
|
+
).freeze
|
47
|
+
|
48
|
+
CALLBACK_METHOD_NAMES.each do |method_name|
|
49
|
+
define_method(method_name) do |*args|
|
50
|
+
super(*args) if defined?(super)
|
51
|
+
end
|
52
|
+
end
|
42
53
|
|
43
54
|
def friend_request(friend)
|
44
55
|
unless self == friend || HasFriendship::Friendship.exist?(self, friend)
|
@@ -88,10 +99,6 @@ module HasFriendship
|
|
88
99
|
HasFriendship::Friendship.find_relation(self, friend, status: 2).any?
|
89
100
|
end
|
90
101
|
|
91
|
-
def on_friendship_created(*args); end
|
92
|
-
def on_friendship_accepted(*args); end
|
93
|
-
def on_friendship_blocked(*args); end
|
94
|
-
|
95
102
|
private
|
96
103
|
|
97
104
|
def has_blocked(friend)
|
@@ -1,8 +1,13 @@
|
|
1
1
|
module HasFriendship
|
2
2
|
class Friendship < ActiveRecord::Base
|
3
|
+
validate :satisfy_custom_conditions
|
3
4
|
|
4
|
-
after_create do
|
5
|
-
friend.on_friendship_created(
|
5
|
+
after_create do |record|
|
6
|
+
friend.on_friendship_created(record)
|
7
|
+
end
|
8
|
+
|
9
|
+
after_destroy do |record|
|
10
|
+
friendable.try(:on_friendship_destroyed, record)
|
6
11
|
end
|
7
12
|
|
8
13
|
enum status: { pending: 0, requested: 1, accepted: 2, blocked: 3 } do
|
@@ -65,5 +70,15 @@ module HasFriendship
|
|
65
70
|
def self.find_one_side(one, other)
|
66
71
|
find_by(relation_attributes(one, other))
|
67
72
|
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def satisfy_custom_conditions
|
77
|
+
return unless friend.respond_to?(:friendship_errors)
|
78
|
+
|
79
|
+
friend.friendship_errors(friendable).to_a.each do |friendship_error|
|
80
|
+
errors.add(:base, friendship_error)
|
81
|
+
end
|
82
|
+
end
|
68
83
|
end
|
69
84
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_friendship
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sung Won Cho
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-12-
|
11
|
+
date: 2018-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|