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 CHANGED
@@ -1,47 +1,37 @@
1
- has_friends
2
- ===========
3
-
4
- **ATTENTION:** This is a new simpler implementation. If you want to use the previous version,
5
- get the 1.0 tag.
6
-
7
- Instalation
8
- -----------
9
-
10
- Install the plugin with
11
-
12
- script/plugin install git://github.com/fnando/has_friends.git
13
-
14
- Then generate a migration with `script/generate migration create_friendships` and add the following code:
15
-
16
- class CreateFriendships < ActiveRecord::Migration
17
- def self.up
18
- create_table :friendships do |t|
19
- t.references :user, :friend
20
- t.datetime :requested_at, :accepted_at, :null => true, :default => nil
21
- t.string :status
22
- end
23
-
24
- add_index :friendships, :user_id
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
 
@@ -14,7 +14,7 @@ module HasFriends
14
14
  end
15
15
 
16
16
  desc "counter", "Adds friends_count column to friendly table"
17
- def counter(tableName = 'User')
17
+ def counter(tableName = 'Users')
18
18
  HasFriends::Generators::FriendsCounter.start([tableName])
19
19
  end
20
20
 
@@ -1,3 +1,3 @@
1
1
  module HasFriends
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_friends
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - embs