popular 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.gemrelease +2 -0
- data/.travis.yml +4 -6
- data/README.md +3 -0
- data/lib/popular/popular.rb +43 -3
- data/lib/popular/version.rb +1 -1
- data/popular.gemspec +1 -0
- data/spec/popular/popular_model_spec.rb +8 -0
- metadata +16 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MDk1NGEzNDZlYjNkZjEzMmFkZTQ1MjFhYmY3YzYxMTk2ZGY2YjdiOA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ODM2MjhhODY1NmJjZjZlMzQzYzljMTM3ZTFkZjExOTgzMDZmMmQxZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ODY5YzY4YzYxNzU5NTc1MzVjNTMwMmE5YzBiOTgzNmQ4MjVjMzE5Y2ExMTIy
|
10
|
+
YmU3YTAxZWY4NmM4YjlmMTIxY2YyN2U2MjNlMjAxNmY3MzRiMDI5ZjVjODA0
|
11
|
+
YTEyM2EwYWI5NjcwMzhkNmZhZjE2MTU2NDlkNWM2ZTg4MTg5ODQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MTcwYjYwMTU4Njk3YTY0YTE1M2JjNmIwMzIyN2QxYzFkZjU5NjQ2ODY1OTFl
|
14
|
+
ZmQxZjE3NjI5MjEwNzBlMzBiNTNkZjk2Mzk5NGU2NmRmMDljZmE4ZWYxNDdk
|
15
|
+
YWNlOWMwODg4ZTZjNTRmZWZlNWQ1ZjkwY2ZhYjI4OWI3ZTEyNWY=
|
data/.gemrelease
ADDED
data/.travis.yml
CHANGED
@@ -1,14 +1,12 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 2.1.0
|
3
|
+
- 2.1.0
|
4
4
|
addons:
|
5
5
|
code_climate:
|
6
|
-
repo_token:
|
6
|
+
repo_token: 4a0d77600a79523f404381dc1cc4bbfb7bf86f897d15b4aa80311db4aad20332
|
7
7
|
deploy:
|
8
8
|
provider: rubygems
|
9
|
-
api_key:
|
10
|
-
secure: lxiDHlutKFERFmsSzhqoGtVGRk06wQIv3Gp7GnvaYdbZzC2tH35tvW4RFxdSWPU8Fp02M8Qc89gV+T0IbAigFZEVp3F7IN4DM09oJWGJ4G1XKykYV0c5aFrEfcPVs4rzxletQanObqbVZqBj/+pCaGA1WvwqojL9Jg6a/w/LhyE=
|
11
|
-
gem: friendly
|
12
9
|
on:
|
13
10
|
tags: true
|
14
|
-
|
11
|
+
api_key:
|
12
|
+
secure: lxiDHlutKFERFmsSzhqoGtVGRk06wQIv3Gp7GnvaYdbZzC2tH35tvW4RFxdSWPU8Fp02M8Qc89gV+T0IbAigFZEVp3F7IN4DM09oJWGJ4G1XKykYV0c5aFrEfcPVs4rzxletQanObqbVZqBj/+pCaGA1WvwqojL9Jg6a/w/LhyE=
|
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# Popular
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/popular.png)](http://badge.fury.io/rb/popular)
|
2
3
|
[![Build Status](https://travis-ci.org/thejchap/popular.svg?branch=master)](https://travis-ci.org/thejchap/popular)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/thejchap/popular.png)](https://codeclimate.com/github/thejchap/popular)
|
5
|
+
[![Code Coverage](https://codeclimate.com/github/thejchap/popular/coverage.png)](https://codeclimate.com/github/thejchap/popular)
|
3
6
|
[![Dependency Status](https://gemnasium.com/thejchap/popular.svg)](https://gemnasium.com/thejchap/popular)
|
4
7
|
|
5
8
|
Popular is a friendship gem designed for Rails/ActiveRecord models.
|
data/lib/popular/popular.rb
CHANGED
@@ -15,14 +15,44 @@ module Popular
|
|
15
15
|
|
16
16
|
# Adds a friend to an instance's friend's list
|
17
17
|
#
|
18
|
-
# @param [
|
18
|
+
# @param [Object] new_friend a popular_model that the instance is not already friends with
|
19
|
+
#
|
20
|
+
# @example
|
21
|
+
# user = User.create name: "Justin"
|
22
|
+
# other_user = User.create name: "Jenny"
|
23
|
+
# user.befriend other_user
|
24
|
+
#
|
25
|
+
# user.friends_with? other_user #=> true
|
19
26
|
def befriend new_friend
|
20
27
|
friendships.create friend: new_friend
|
21
28
|
end
|
22
29
|
|
30
|
+
# Adds a friend to an instance's friend's list
|
31
|
+
# Similar to .befriend, but will raise an error if the operation is not successful
|
32
|
+
#
|
33
|
+
# @param [Object] new_friend a popular_model that the instance is not already friends with
|
34
|
+
#
|
35
|
+
# @example
|
36
|
+
# user = User.create name: "Justin"
|
37
|
+
# other_user = User.create name: "Jenny"
|
38
|
+
# user.befriend! other_user
|
39
|
+
# user.reload
|
40
|
+
# user.friends_with? other_user # => true
|
41
|
+
def befriend! new_friend
|
42
|
+
friendships.create! friend: new_friend
|
43
|
+
end
|
44
|
+
|
23
45
|
# Removes a friend from an instance's friend's list
|
24
46
|
#
|
25
|
-
# @param [
|
47
|
+
# @param [Object] friend a popular_model in this instance's friends list
|
48
|
+
#
|
49
|
+
# @example
|
50
|
+
# user = User.create name: "Justin"
|
51
|
+
# other_user = User.create name: "Jenny"
|
52
|
+
# user.befriend other_user
|
53
|
+
# user.unfriend other_user
|
54
|
+
#
|
55
|
+
# user.friends_with? other_user # => false
|
26
56
|
def unfriend friend
|
27
57
|
friendships.where( friend: friend ).first.destroy
|
28
58
|
end
|
@@ -30,8 +60,18 @@ module Popular
|
|
30
60
|
# Helper method for finding whether or not the instance is friends with
|
31
61
|
# another given popular_model
|
32
62
|
#
|
33
|
-
# @param [
|
63
|
+
# @param [Object] popular_model
|
34
64
|
# @return [Boolean] if the instance has popular_model as a friend
|
65
|
+
#
|
66
|
+
# @example
|
67
|
+
# user = User.create name: "Justin"
|
68
|
+
# other_user = User.create name: "Jenny"
|
69
|
+
#
|
70
|
+
# user.friends_with? other_user #=> false
|
71
|
+
#
|
72
|
+
# user.befriend other_user
|
73
|
+
#
|
74
|
+
# user.friends_with? other_user #=> true
|
35
75
|
def friends_with? popular_model
|
36
76
|
friendships.where( friend: popular_model ).any?
|
37
77
|
end
|
data/lib/popular/version.rb
CHANGED
data/popular.gemspec
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
shared_examples "a popular model" do
|
2
2
|
|
3
|
+
describe '.befriend!' do
|
4
|
+
it 'creates a one way friendship' do
|
5
|
+
popular_model.befriend! another_popular_model
|
6
|
+
|
7
|
+
expect( popular_model.friends ).to match_array [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
|
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.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- thejchap
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - ~>
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0.3'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: gem-release
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ~>
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.7.1
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ~>
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.7.1
|
125
139
|
description: Friendship gem for Rails/ActiveRecord. Popular saves time when developing
|
126
140
|
social apps
|
127
141
|
email:
|
@@ -130,6 +144,7 @@ executables: []
|
|
130
144
|
extensions: []
|
131
145
|
extra_rdoc_files: []
|
132
146
|
files:
|
147
|
+
- .gemrelease
|
133
148
|
- .gitignore
|
134
149
|
- .rspec
|
135
150
|
- .travis.yml
|