popular 0.4.0 → 0.5.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 +8 -8
- data/lib/popular.rb +0 -2
- data/lib/popular/popular.rb +23 -10
- data/lib/popular/version.rb +1 -1
- data/spec/popular/popular_model_spec.rb +8 -0
- data/spec/popular/popular_spec.rb +0 -1
- data/spec/support/popular_model_with_callbacks.rb +1 -3
- metadata +1 -3
- data/spec/support/random_class.rb +0 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NWE5Mjc5N2Q5YjVlNzc2OTM5ODM0MjdlYzkwNmJlOWQ1NTI5MGQ1Mg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZTdhZGY1MjM0MDdhNjM5NDZhODhiNTRkNzYwOTMzODRlY2EyNjM4OQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OWJjMTBiYjRlOGNkN2NhMmQxYjEyYWJiZGNmOWNkYmQ2ZDhmYTQzOWZkODgw
|
10
|
+
YTk5MWE1ZTFkMzNkZTliMmNkYTE1ZGUxYzE2YzJjMzNjODllNTUzNDAzODM4
|
11
|
+
YTE3MzNhMTRhNWMzOGVmOTliMDlhZjExNWJlMDA4OGYwZTY4ZTk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZWM0NGMwM2RjOGY3N2Y0NjE5OGQ3MDc1ZTcyNmI0N2Y2MzA1MjFlZWE0ZDg2
|
14
|
+
YjNmZjQ2ZmEyMjhiZDg3ZGM3YmFjZmM2MzJjYzk5ZWUxYTgzNjRjMTlmZGRl
|
15
|
+
NzY4ODI4YTBiZTM5ZTU2NWZlNThhNzJhNmIyMTBhM2NlNTZmNTA=
|
data/lib/popular.rb
CHANGED
data/lib/popular/popular.rb
CHANGED
@@ -7,6 +7,8 @@ module Popular
|
|
7
7
|
included do |base|
|
8
8
|
has_many :friendships, class_name: 'Popular::Friendship', as: :popular_model, dependent: :destroy
|
9
9
|
has_many :friends, through: :friendships, source_type: base
|
10
|
+
has_many :inverse_friendships, class_name: 'Popular::Friendship', as: :friend, foreign_key: :friend_id
|
11
|
+
has_many :inverse_friends, through: :inverse_friendships, source: :popular_model, source_type: base
|
10
12
|
|
11
13
|
include ActiveSupport::Callbacks
|
12
14
|
define_callbacks :befriend, :unfriend
|
@@ -66,7 +68,26 @@ module Popular
|
|
66
68
|
end
|
67
69
|
end
|
68
70
|
|
69
|
-
# Helper method for finding whether or not the instance
|
71
|
+
# Helper method for finding whether or not the instance has
|
72
|
+
# been befriended by another given popular_model
|
73
|
+
#
|
74
|
+
# @param [Object] popular_model
|
75
|
+
# @return [Boolean] if the instance has been friended by another popular_model
|
76
|
+
#
|
77
|
+
# @example
|
78
|
+
# user = User.create name: "Justin"
|
79
|
+
# other_user = User.create name: "Jenny"
|
80
|
+
#
|
81
|
+
# user.friended_by? other_user #=> false
|
82
|
+
#
|
83
|
+
# other_user.befriend user
|
84
|
+
#
|
85
|
+
# user.friended_by? other_user #=> true
|
86
|
+
def friended_by? popular_model
|
87
|
+
inverse_friends.include? popular_model
|
88
|
+
end
|
89
|
+
|
90
|
+
# Helper method for finding whether or not the instance has befriended
|
70
91
|
# another given popular_model
|
71
92
|
#
|
72
93
|
# @param [Object] popular_model
|
@@ -82,7 +103,7 @@ module Popular
|
|
82
103
|
#
|
83
104
|
# user.friends_with? other_user #=> true
|
84
105
|
def friends_with? popular_model
|
85
|
-
|
106
|
+
friends.include? popular_model
|
86
107
|
end
|
87
108
|
|
88
109
|
# ClassMethods included in popular models
|
@@ -90,8 +111,6 @@ module Popular
|
|
90
111
|
|
91
112
|
# after_unfriend callback convenience class method
|
92
113
|
#
|
93
|
-
# @since 0.4.0
|
94
|
-
#
|
95
114
|
# @example
|
96
115
|
#
|
97
116
|
# class User < ActiveRecord::Base
|
@@ -113,8 +132,6 @@ module Popular
|
|
113
132
|
|
114
133
|
# before_unfriend callback convenience class method
|
115
134
|
#
|
116
|
-
# @since 0.4.0
|
117
|
-
#
|
118
135
|
# @example
|
119
136
|
#
|
120
137
|
# class User < ActiveRecord::Base
|
@@ -136,8 +153,6 @@ module Popular
|
|
136
153
|
|
137
154
|
# before_befriend callback convenience class method
|
138
155
|
#
|
139
|
-
# @since 0.3.0
|
140
|
-
#
|
141
156
|
# @example
|
142
157
|
#
|
143
158
|
# class User < ActiveRecord::Base
|
@@ -158,8 +173,6 @@ module Popular
|
|
158
173
|
|
159
174
|
# after_befriend callback convenience class method
|
160
175
|
#
|
161
|
-
# @since 0.3.0
|
162
|
-
#
|
163
176
|
# @example
|
164
177
|
#
|
165
178
|
# class User < ActiveRecord::Base
|
data/lib/popular/version.rb
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
shared_examples "a popular model" do
|
2
2
|
|
3
|
+
describe 'mutual friendships' do
|
4
|
+
it '.inverse_friends includes popular_models who have added an instance as a friend' do
|
5
|
+
another_popular_model.befriend popular_model
|
6
|
+
|
7
|
+
expect( popular_model ).to be_friended_by another_popular_model
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
3
11
|
describe '.befriend!' do
|
4
12
|
it 'creates a one way friendship' do
|
5
13
|
popular_model.befriend! another_popular_model
|
@@ -15,7 +15,6 @@ describe Popular::Popular do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
it_behaves_like 'a popular model' do
|
18
|
-
let ( :random_object ) { RandomClass.new }
|
19
18
|
let ( :popular_model ) { PopularModel.create }
|
20
19
|
let ( :another_popular_model ) { PopularModel.create }
|
21
20
|
let ( :popular_model_with_callbacks ) { PopularModelWithCallbacks.create }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: popular
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- thejchap
|
@@ -168,7 +168,6 @@ files:
|
|
168
168
|
- spec/spec_helper.rb
|
169
169
|
- spec/support/popular_model.rb
|
170
170
|
- spec/support/popular_model_with_callbacks.rb
|
171
|
-
- spec/support/random_class.rb
|
172
171
|
- spec/support/unpopular_model.rb
|
173
172
|
homepage: http://thejchap.github.io/popular
|
174
173
|
licenses:
|
@@ -202,6 +201,5 @@ test_files:
|
|
202
201
|
- spec/spec_helper.rb
|
203
202
|
- spec/support/popular_model.rb
|
204
203
|
- spec/support/popular_model_with_callbacks.rb
|
205
|
-
- spec/support/random_class.rb
|
206
204
|
- spec/support/unpopular_model.rb
|
207
205
|
has_rdoc:
|
@@ -1 +0,0 @@
|
|
1
|
-
RandomClass = Class.new
|