has_friendship 1.0.2 → 1.1.0

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: beeb114cb3e5a0439b099e7bd2d957a6c9341208
4
- data.tar.gz: 1ffb7ab87dda1a4413aae89e92d3891e225ead83
3
+ metadata.gz: 9132e28ff843795c0c0a75a2a9a87d8924ce6b04
4
+ data.tar.gz: 082d2aca63456254542c02704e84caf9429fdd02
5
5
  SHA512:
6
- metadata.gz: f7093c9282d5f78edf7e88e511ddde981f2e18615339ca434412d722c8e73656df913fb4a46fb94bcc3903e85a0574020c793576f4f67386f521396ae75bb1c1
7
- data.tar.gz: ac6407df6de729e7a0badc49423b9be8494ab076222b2f409fe04c6113061ce4b52db110abebb60c175b88e500327d7f0b978012284ac7a422f33e602ae7b88e
6
+ metadata.gz: 4a19f13fb2a2ad003fb169abebf782af9df68bd70d1e2cba6fb5dbdc8f5568949cce12c5d8422e6ed89ecd84f7bfe1834df8f8112ae0159da84e246cd9749f68
7
+ data.tar.gz: e5c234f06331dbefbb97cec124d9d493e4de5646994e150e13a6d2ae2261790a3dd193d1c3e184b97a2920396482964804f024d3d00519847736f032af34f845
@@ -51,7 +51,8 @@ module HasFriendship
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).accept!
54
+ friendship = HasFriendship::Friendship.find_unblocked_friendship(one, other)
55
+ friendship.accept! if can_accept_request?(friendship)
55
56
  end
56
57
  end
57
58
 
@@ -87,11 +88,22 @@ module HasFriendship
87
88
  HasFriendship::Friendship.find_relation(self, friend, status: 2).any?
88
89
  end
89
90
 
91
+ def on_friendship_created(*args); end
92
+ def on_friendship_accepted(*args); end
93
+ def on_friendship_blocked(*args); end
94
+
90
95
  private
91
96
 
92
97
  def has_blocked(friend)
93
98
  HasFriendship::Friendship.find_one_side(self, friend).blocker_id == self.id
94
99
  end
100
+
101
+ def can_accept_request?(friendship)
102
+ return if friendship.pending? && self == friendship.friendable
103
+ return if friendship.requested? && self == friendship.friend
104
+
105
+ true
106
+ end
95
107
  end
96
108
  end
97
109
  end
@@ -1,9 +1,17 @@
1
1
  module HasFriendship
2
2
  class Friendship < ActiveRecord::Base
3
3
 
4
+ after_create do
5
+ friend.on_friendship_created(self)
6
+ end
7
+
4
8
  enum status: { pending: 0, requested: 1, accepted: 2, blocked: 3 } do
5
9
  event :accept do
6
10
  transition [:pending, :requested] => :accepted
11
+
12
+ after do
13
+ friendable.on_friendship_accepted(self)
14
+ end
7
15
  end
8
16
 
9
17
  event :block do
@@ -11,6 +19,9 @@ module HasFriendship
11
19
  self.blocker_id = self.friendable.id
12
20
  end
13
21
 
22
+ after do
23
+ friendable.on_friendship_blocked(self)
24
+ end
14
25
  transition all - [:blocked] => :blocked
15
26
  end
16
27
  end
@@ -1,3 +1,3 @@
1
1
  module HasFriendship
2
- VERSION = "1.0.2"
2
+ VERSION = "1.1.0"
3
3
  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.0.2
4
+ version: 1.1.0
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-06-01 00:00:00.000000000 Z
11
+ date: 2017-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -195,7 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
195
  version: '0'
196
196
  requirements: []
197
197
  rubyforge_project:
198
- rubygems_version: 2.4.7
198
+ rubygems_version: 2.5.1
199
199
  signing_key:
200
200
  specification_version: 4
201
201
  summary: Add social network friendship features to your Active Record models.