has_friends 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +52 -42
- data/lib/has_friends/cli.rb +1 -1
- data/lib/has_friends/version.rb +1 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -1,47 +1,37 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
add_index :friendships, :friend_id
|
26
|
-
add_index :friendships, :status
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.down
|
30
|
-
drop_table :friendships
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
Finally, run the migrations with `rake db:migrate`
|
35
|
-
|
36
|
-
Usage
|
37
|
-
-----
|
1
|
+
# Installation
|
2
|
+
|
3
|
+
```ruby
|
4
|
+
# Gemfile
|
5
|
+
gem 'has_friends'
|
6
|
+
```
|
7
|
+
Then run `bundle`.
|
8
|
+
Alternatively
|
9
|
+
```
|
10
|
+
gem install has_friends
|
11
|
+
```
|
12
|
+
Then you need add `has_friends` method to your User model and generate friendship migration with
|
13
|
+
```
|
14
|
+
has_friends install
|
15
|
+
```
|
16
|
+
and run `rake db:migrate` in order to migrate the new generated migration.
|
17
|
+
Case your User model has no `friends_count` column in it's table, you can easily generate a migration
|
18
|
+
to accomplish this with
|
19
|
+
```
|
20
|
+
has_friends counter
|
21
|
+
```
|
22
|
+
and run `rake db:migrate` again.
|
23
|
+
|
24
|
+
# Usage
|
38
25
|
|
39
26
|
Add the method call `has_friends` to your model.
|
40
|
-
|
27
|
+
```ruby
|
41
28
|
class User < ActiveRecord::Base
|
42
29
|
has_friends
|
43
30
|
end
|
31
|
+
```
|
44
32
|
|
33
|
+
# Common tasks
|
34
|
+
```ruby
|
45
35
|
john = User.find_by_login 'john'
|
46
36
|
mary = User.find_by_login 'mary'
|
47
37
|
paul = User.find_by_login 'paul'
|
@@ -94,10 +84,30 @@ Add the method call `has_friends` to your model.
|
|
94
84
|
else
|
95
85
|
# ...
|
96
86
|
end
|
87
|
+
```
|
97
88
|
|
98
|
-
NOTE: You should have a User model. You should also have a `friends_count` column
|
99
|
-
on your model. Otherwise, this won't work! Create a new migration with `script/generate migration add_friends_count_to_user`:
|
100
89
|
|
90
|
+
# Generated Migrations
|
91
|
+
```ruby
|
92
|
+
class CreateFriendships < ActiveRecord::Migration
|
93
|
+
def self.up
|
94
|
+
create_table :friendships do |t|
|
95
|
+
t.references :user, :friend
|
96
|
+
t.datetime :requested_at, :accepted_at, :null => true, :default => nil
|
97
|
+
t.string :status
|
98
|
+
end
|
99
|
+
|
100
|
+
add_index :friendships, :user_id
|
101
|
+
add_index :friendships, :friend_id
|
102
|
+
add_index :friendships, :status
|
103
|
+
end
|
104
|
+
|
105
|
+
def self.down
|
106
|
+
drop_table :friendships
|
107
|
+
end
|
108
|
+
end
|
109
|
+
```
|
110
|
+
```ruby
|
101
111
|
class AddFriendsCountToUser < ActiveRecord::Migration
|
102
112
|
def self.up
|
103
113
|
add_column :users, :friends_count, :integer, :default => 0, :null => false
|
@@ -107,9 +117,9 @@ on your model. Otherwise, this won't work! Create a new migration with `script/g
|
|
107
117
|
remove_column :users, :friends_count
|
108
118
|
end
|
109
119
|
end
|
120
|
+
```
|
110
121
|
|
111
|
-
LICENSE:
|
112
|
-
--------
|
122
|
+
# LICENSE:
|
113
123
|
|
114
124
|
(The MIT License)
|
115
125
|
|
data/lib/has_friends/cli.rb
CHANGED
data/lib/has_friends/version.rb
CHANGED
metadata
CHANGED