popular 0.5.0 → 0.5.1
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/README.md +12 -5
- data/lib/popular/popular.rb +20 -0
- data/lib/popular/version.rb +1 -1
- data/spec/popular/popular_model_spec.rb +11 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NWQyNWFkOTY3ZjlhNTY0Y2JhZTFmZjM4NGUxNmQ1YjZjZjhlYmRkMg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ODhhNmU2ZDc1ODU0NGU2YjU1Zjc0ZjU1YjFjYWQyZTlhMmIyNDkwMg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
M2NjNzI0MGY5NTQyZGYxNDZiNGJjMDZhZWQ4YmIxYWI2MDM5YTY3MjhiZDkx
|
10
|
+
MzhjYzM5ZjNhYzA1OWQzN2Y2ZTc2NTFiN2U1NDMyZGRjZTViNTk0NTgxMDcw
|
11
|
+
MTlkZmRhZDM4NzAxYjQyMWRhNGYzY2QwODRiN2EwZTAyOWM2MWE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YjJmYmNkZGQxYzA2Zjk4NjJjZDcyNjU3YzIyOTEwMjhhYjk0OGVmMDJiOWY3
|
14
|
+
NzUzNTk4ZjE3ZmVhYTA4MzM1NWIyZmUxMDc5NTAyMzA5MjU2NjA0NWE3ZGE1
|
15
|
+
NGI2NmFjNzk3MzBmNTQ0ZjczMWU0NzlmMTQzOTc3MmRiNDM0ZTM=
|
data/README.md
CHANGED
@@ -45,13 +45,20 @@ end
|
|
45
45
|
@jackson = User.create name: "Jackson"
|
46
46
|
|
47
47
|
# Adding and removing friends
|
48
|
-
@sam.friends_with? @jackson
|
49
|
-
@sam.
|
48
|
+
@sam.friends_with? @jackson #=> false
|
49
|
+
@sam.friended_by? @jackson #=> false
|
50
|
+
|
50
51
|
@sam.befriend @jackson
|
51
|
-
@sam.friends_with? @jackson
|
52
|
-
|
52
|
+
@sam.friends_with? @jackson #=> true
|
53
|
+
|
53
54
|
@sam.unfriend @jackson
|
54
|
-
@sam.friends_with? @jackson
|
55
|
+
@sam.friends_with? @jackson #=> false
|
56
|
+
|
57
|
+
@jackson.befriend @sam
|
58
|
+
@sam.friended_by? @jackson #=> true
|
59
|
+
|
60
|
+
@sam.befriend @jackson
|
61
|
+
@sam.mutual_friends_with? @jackson #=> true
|
55
62
|
```
|
56
63
|
|
57
64
|
### Callbacks
|
data/lib/popular/popular.rb
CHANGED
@@ -68,6 +68,26 @@ module Popular
|
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
+
# Helper method for determining whether instances are mutual friends
|
72
|
+
#
|
73
|
+
# @param [Object] popular_model
|
74
|
+
# @return [Boolean] if both instances have befriended eachother
|
75
|
+
#
|
76
|
+
# @example
|
77
|
+
# user = User.create name: "Justin"
|
78
|
+
# other_user = User.create name: "Jenny"
|
79
|
+
#
|
80
|
+
# user.befriend other_user
|
81
|
+
# other_user.befriend user
|
82
|
+
#
|
83
|
+
# user.mutual_friends_with? other_user #=> true
|
84
|
+
def mutual_friends_with? popular_model
|
85
|
+
friends_with?( popular_model ) && friended_by?( popular_model )
|
86
|
+
end
|
87
|
+
|
88
|
+
# Helper method for finding whether or not the instance has befriended
|
89
|
+
# another given popular_model
|
90
|
+
#
|
71
91
|
# Helper method for finding whether or not the instance has
|
72
92
|
# been befriended by another given popular_model
|
73
93
|
#
|
data/lib/popular/version.rb
CHANGED
@@ -6,6 +6,17 @@ shared_examples "a popular model" do
|
|
6
6
|
|
7
7
|
expect( popular_model ).to be_friended_by another_popular_model
|
8
8
|
end
|
9
|
+
|
10
|
+
it '#mutual_friends_with? returns false if instances are not mutual friends' do
|
11
|
+
expect( popular_model ).to_not be_mutual_friends_with another_popular_model
|
12
|
+
end
|
13
|
+
|
14
|
+
it '#mutual_friends_with? returns true if instances have befriended eachother' do
|
15
|
+
popular_model.befriend another_popular_model
|
16
|
+
another_popular_model.befriend popular_model
|
17
|
+
|
18
|
+
expect( popular_model ).to be_mutual_friends_with another_popular_model
|
19
|
+
end
|
9
20
|
end
|
10
21
|
|
11
22
|
describe '.befriend!' do
|