Skip to content

Commit

Permalink
updated the documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
raw1z committed Mar 6, 2012
1 parent 621bd3f commit e9c16bd
Showing 1 changed file with 4 additions and 127 deletions.
131 changes: 4 additions & 127 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -14,137 +14,14 @@ Then run:

## Usage ##

If you are using ActiveRecord, you need to generate a friendship model. Amistad has a generator for this task :

rails generate amistad:install

This command creates a new model called __friendship__ in *'app/models'* :

class Friendship < ActiveRecord::Base
include Amistad::FriendshipModel
end

It also creates a new migration for the friendship model so don't forget to migrate your database :

rake db:migrate

If you are using Mongoid, you don't need a friendship model. Finally, activate __amistad__ in your user model :

class User < ActiveRecord::Base
include Amistad::FriendModel
end

or :

class User
include Mongoid::Document
include Amistad::FriendModel
end

## Friendships management ##

### Creating friendships ###
To create a new friendship with another user use the method called __invite()__ :

@john.invite @jane
@peter.invite @john
@peter.invite @jane
@victoria.invite @john

The __invite()__ method return *true* if the friendship successfully created, otherwise it returns *false*. The friendships remain in pending state until they are approved by the user requested. To approve the friendship created above use the method called __approve()__ :

@jane.approve @john
@john.approve @peter
@jane.approve @peter

As __invite()__, __approve()__ return *true* if the friendship was successfuly approved or *false* if not.

### Listing friends ###

There are two types of friends in __amistad__ :

- the friends who were invited by the user
- the friends who invited the user

To get the friend who where invited by __@john__, use the __invited()__ method :

@john.invited #=> [@jane]

To get the friends who invited __@john__, use the __invited_by()__ method :

@john.invited_by #=> [@peter]

To get all the friends of __@john__ (those he invited and those who invited him) :

@john.friends #=> [@jane, @peter]

To get the pending friendships use :

@victoria.pending_invited #=> [@john]
@john.pending_invited_by #=> [@victoria]

It is also possible to check if two users are friends :

@john.friend_with? @jane #=> true
@victoria.friend_with? @john #=> false

You can also check if a user is somehow connected to another :

@john.connected_with? @jane #=> true
@victoria.connected_with? @john #=> true

You can also check if a user was invited by anoter :

@john.invited_by? @john #=> true
@victoria.invited_by? @john #=> false

You can also check if a user invited another :

@john.invited? @jane #=> true

You can also find the friends that two users have in common :

@john.common_friends_with(@peter) #=> [@jane]

### Removing friendships ###

The __remove_friendship()__ method allow a user to remove its friendships :

@john.remove_friendship @jane
@john.remove_friendship @peter
@john.remove_friendship @victoria

### Blocking friendships ###

The __block()__ method allow a user to block a friendship with another user :

@john.invite @jane
@jane.block @john

To get the blocked users :

@jane.blocked #=> [@john]

You can also check if a user is blocked :

@jane.blocked? @john #=> true

### Unblocking friendship ###

The __unblock()__ method allow a user to unblock previously blocked friendship with another user :

@jane.block @john
@jane.blocked #=> [@john]

@jane.unblock @john
@jane.blocked #=> []
Refer to the wiki pages for usage and friendships management.

## Testing ##

It is possible to test amistad by running one of the following commands from the gem directory:

rspec spec/activerecord/ # activerecord tests
rspec spec/mongoid/ # mongoid tests
rspec spec/activerecord # activerecord tests
rspec spec/mongoid # mongoid tests

Remember that amistad is only compatible with ActiveRecord 3.0.x and Mongoid 2.0.x.

Expand All @@ -156,7 +33,7 @@ You can also run `rake` by itself and it will run the ActiveRecord tests followe
* Adrian Dulić : unblock friendships (and many other improvements)

## Note on Patches/Pull Requests ##

* Fork the project.
* Make your feature addition or bug fix.
* Add tests for it. This is important so I don't break it in a future version unintentionally.
Expand Down

0 comments on commit e9c16bd

Please sign in to comment.