A Gem to add Follow functionality for models
A Gem to add Follow functionality for models
= acts_as_follower
acts_as_follower is a gem to allow any model to follow any other model. This is accomplished through a double polymorphic relationship on the Follow model. There is also built in support for blocking/un-blocking follow records.
Main uses would be for Users to follow other Users or for Users to follow Books, etc...
(Basically, to develop the type of follow system that GitHub has)
{}[https://travis-ci.org/tcocca/acts_as_follower]
== Installation
=== The master branch supports Rails 5
Add the gem to the gemfile: gem 'acts_as_follower', github: 'tcocca/acts_as_follower', branch: 'master'
Other instructions same as for Rails 4.
=== Rails 4.x support
The first release that support Rails 4 is 0.2.0
Add the gem to the gemfile: gem "acts_as_follower"
Run the generator: rails generate acts_as_follower
This will generate a migration file as well as a model called Follow.
=== Rails 3.x support
Rails 3 is supports in the rails_3 branch https://github.com/tcocca/acts_as_follower/tree/rails_3 The last gem release for Rails 3 support was 0.1.1, so install the gem using ~> 0.1.1
Add the gem to the gemfile: gem "acts_as_follower", '~> 0.1.1'
or install from the branch
gem "acts_as_follower", git: 'git://github.com/tcocca/acts_as_follower.git', branch: 'rails_3'
Run the generator: rails generate acts_as_follower
This will generate a migration file as well as a model called Follow.
=== Rails 2.3.x support
Rails 2.3.x is supported in the rails_2.3.x branch http://github.com/tcocca/acts_as_follower/tree/rails_2.3.x but must be installed as a plugin. The gem version does not work with rails 2.3.x.
Run the following command: script/plugin install git://github.com/tcocca/acts_as_follower.git -r rails_2.3.x
Run the generator: script/generate acts_as_follower
== Usage
=== Setup
Make your model(s) that you want to allow to be followed acts_as_followable, just add the mixin: class User false the follow is deleted. So, a user would need to try and follow the book again. I would like to hear thoughts on this, I may change this to make the follow as blocked: false instead of deleting the record.
=== Follow Model
The Follow model has a set of named_scope's. In case you want to interface directly with the Follow model you can use them. Follow.unblocked # returns all "unblocked" follow records
Follow.blocked # returns all "blocked" follow records
Follow.descending # returns all records in a descending order based on created_at datetime
This method pulls all records created after a certain date. The default is 2 weeks but it takes an optional parameter. Follow.recent Follow.recent(4.weeks.ago)
Follow.for_follower is a named_scope that is mainly there to reduce code in the modules but it could be used directly. It takes an object and will return all Follow records where the follower is the record passed in. Note that this will return all blocked and unblocked records. Follow.for_follower(user) If you don't need the blocked records just use the methods provided for this: user.all_follows
user.all_following
Follow.for_followable acts the same as its counterpart (for_follower). It is mainly there to reduce duplication, however it can be used directly. It takes an object that is the followed object and return all Follow records where that record is the followable. Again, this returns all blocked and unblocked records. Follow.for_followable(book) Again, if you don't need the blocked records use the method provided for this: book.followers If you need blocked records only book.blocks
== Comments/Requests
If anyone has comments or questions please let me know (tom dot cocca at gmail dot com). If you have updates or patches or want to contribute I would love to see what you have or want to add.
== Note on Patches/Pull Requests
== Contributers
Thanks to everyone for their interest and time in committing to making this plugin better.
Please let me know if I missed you.
== Copyright
Copyright (c) 2008 - 2010 ( tom dot cocca at gmail dot com ), released under the MIT license.
No open issues yet, or sync has not completed.