has_followers <img src=“https://secure.travis-ci.org/fabianoalmeida/has_followers.png” />
ATTENTION: This is a Rails 3 implementation.
NOTE: It’s necessary there’s a User model. When is executing the migration this gem will create two columns in users’ table: followeds_count
and followers_count
.
Instalation
-
The first step is add this gem to your Gemfile
gem 'has_followers'
-
After that, install the gem in your development environment
bundle install
-
Execute the migration generator to create tables and columns necessary
rails g has_followers:migration
-
Run the migrations with
rake db:migrate
Usage
It’s very simple to use this gem. See the examples below.
To follow someone you need only do this
you.follow(someone)
This action automatically increment your followeds_count
column and his (someone) followers_count
column too.
Cause you want to unfollow someone, no problem. It’s similar to follow someone
you.unfollow(someone)
When you unfollow
someone, this automatically decrement your followeds_count
column and his (someone) followers_count
column too.
You can check how many users you is following
you.followeds_count
Or how many users are following you
you.follwers_count
If you want to know who are your followeds users
you.followeds
And your followers
you.followers
Check if the user is you
you.is?(someone) # => true if someone is you
If you want to know if you is following someone
you.following?(someone) # => Follow object if you already following someone
There’s a user that you want to know whether he is following you
you.follow_me?(someone) # => Follow object if he is following you
Or cause you want to know which relationship between you and your followed or follower
you.following_for(someone)
Or
you.followed_for(someone)
The first one will finding on your followeds list, however the second one will find on your followers list.
Contributing to has_followers
-
Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet
-
Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it
-
Fork the project
-
Start a feature/bugfix branch
-
Commit and push until you are happy with your contribution
-
Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.
-
Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
Copyright
Copyright © 2012 Fabiano Almeida. See LICENSE.txt for further details.