has_friendship 0.1.3 → 0.1.4
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 498832a304c1e5234ed5ed576727d2f98a236b50
|
4
|
+
data.tar.gz: 4cf1a787e0e8034df4351707dd086c5409dde83c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9319fd2d7592610e5e2c040c84f8083d2526d848ddc2ac84fea1e286e62b13a593922526c676d71963a69b065e4b6d5c089e2415d28c38ffddd4f162f8910fb
|
7
|
+
data.tar.gz: 889c71eb0c6ae727428041b430c1eb3a61ddc7f3082efc5158587fab5ba1994aa328b0a749c28a47ac9bcf9ef3c57cba8f94f35fa5e1715bb4fc2d390717bb4a
|
@@ -11,21 +11,21 @@ module HasFriendship
|
|
11
11
|
class_name: "HasFriendship::Friendship", dependent: :destroy
|
12
12
|
|
13
13
|
has_many :blocked_friends,
|
14
|
-
-> { where friendships: { status:
|
14
|
+
-> { where friendships: { status: 3 } },
|
15
15
|
through: :friendships,
|
16
16
|
source: :friend
|
17
17
|
|
18
18
|
has_many :friends,
|
19
|
-
-> { where friendships: { status:
|
19
|
+
-> { where friendships: { status: 2 } },
|
20
20
|
through: :friendships
|
21
21
|
|
22
22
|
has_many :requested_friends,
|
23
|
-
-> { where friendships: { status:
|
23
|
+
-> { where friendships: { status: 1 } },
|
24
24
|
through: :friendships,
|
25
25
|
source: :friend
|
26
26
|
|
27
27
|
has_many :pending_friends,
|
28
|
-
-> { where friendships: { status:
|
28
|
+
-> { where friendships: { status: 0 } },
|
29
29
|
through: :friendships,
|
30
30
|
source: :friend
|
31
31
|
|
@@ -43,16 +43,15 @@ module HasFriendship
|
|
43
43
|
def friend_request(friend)
|
44
44
|
unless self == friend || HasFriendship::Friendship.exist?(self, friend)
|
45
45
|
transaction do
|
46
|
-
HasFriendship::Friendship.create_relation(self, friend, status:
|
47
|
-
HasFriendship::Friendship.create_relation(friend, self, status:
|
46
|
+
HasFriendship::Friendship.create_relation(self, friend, status: 0)
|
47
|
+
HasFriendship::Friendship.create_relation(friend, self, status: 1)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
def accept_request(friend)
|
53
53
|
on_relation_with(friend) do |one, other|
|
54
|
-
HasFriendship::Friendship.find_unblocked_friendship(one, other)
|
55
|
-
.update(status: 'accepted')
|
54
|
+
HasFriendship::Friendship.find_unblocked_friendship(one, other).accept!
|
56
55
|
end
|
57
56
|
end
|
58
57
|
|
@@ -66,8 +65,7 @@ module HasFriendship
|
|
66
65
|
|
67
66
|
def block_friend(friend)
|
68
67
|
on_relation_with(friend) do |one, other|
|
69
|
-
HasFriendship::Friendship.find_unblocked_friendship(one, other)
|
70
|
-
.update(status: 'blocked', blocker_id: self.id)
|
68
|
+
HasFriendship::Friendship.find_unblocked_friendship(one, other).block!
|
71
69
|
end
|
72
70
|
end
|
73
71
|
|
@@ -86,7 +84,7 @@ module HasFriendship
|
|
86
84
|
end
|
87
85
|
|
88
86
|
def friends_with?(friend)
|
89
|
-
HasFriendship::Friendship.find_relation(self, friend, status:
|
87
|
+
HasFriendship::Friendship.find_relation(self, friend, status: 2).any?
|
90
88
|
end
|
91
89
|
|
92
90
|
private
|
@@ -1,5 +1,20 @@
|
|
1
1
|
module HasFriendship
|
2
2
|
class Friendship < ActiveRecord::Base
|
3
|
+
|
4
|
+
enum status: { pending: 0, requested: 1, accepted: 2, blocked: 3 } do
|
5
|
+
event :accept do
|
6
|
+
transition [:pending, :requested] => :accepted
|
7
|
+
end
|
8
|
+
|
9
|
+
event :block do
|
10
|
+
before do
|
11
|
+
self.blocker_id = self.friendable.id
|
12
|
+
end
|
13
|
+
|
14
|
+
transition all - [:blocked] => :blocked
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
3
18
|
def self.relation_attributes(one, other, status: nil)
|
4
19
|
attr = {
|
5
20
|
friendable_id: one.id,
|
@@ -29,11 +44,11 @@ module HasFriendship
|
|
29
44
|
end
|
30
45
|
|
31
46
|
def self.find_unblocked_friendship(friendable, friend)
|
32
|
-
find_relation(friendable, friend).where.not(status:
|
47
|
+
find_relation(friendable, friend).where.not(status: 3).first
|
33
48
|
end
|
34
49
|
|
35
50
|
def self.find_blocked_friendship(friendable, friend)
|
36
|
-
find_relation(friendable, friend).where(status:
|
51
|
+
find_relation(friendable, friend).where(status: 3).first
|
37
52
|
end
|
38
53
|
|
39
54
|
def self.find_one_side(one, other)
|
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: 0.1.
|
4
|
+
version: 0.1.4
|
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: 2016-04-
|
11
|
+
date: 2016-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '4.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: stateful_enum
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: sqlite3
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|