No commit activity in last 3 years
No release in over 3 years
Please refer to http://rubygems.org/gems/mongo_followable for latest versions
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3.0
~> 2.0.1
~> 2.6
 Project Readme

mongoid_followable¶ ↑

Please refer to mongo_followable for latest version.

Installation¶ ↑

In console:

gem install mongoid_followable

or in Gemfile:

gem 'mongoid_followable', "~> 0.1.9"

Usage¶ ↑

To make model followable you need to include Mongoid::Followable into your document;Meanwhile, you also need to include Mongoid::Follower in your follower model:

class User
  include Mongoid::Document
  include Mongoid::Followable
  include Mongoid::Follower
end

class Group
  include Mongoid::Document
  include Mongoid::Followable
end

Now you can set authorization:

current_user.set_authorization('user', 'game') # now current_user cannot follow User and Game model
current_user.unset_authorization('User', 'Game')

And then you can follow a model:

@group = Group.new
@group.save

current_user.follow(@group)
current_user.unfollow(@group)

You can also judge whether a model is a follower of another model or a model is a followee of another model:

	
current_user.follower_of?(@group)
current_user.followee_of?(@group)

Moreover, it’s easy to get a model’s follower/followee count:

current_user.followers_count
current_user.followees_count

Of course, you can get a list of followers/followees:

	
User.followers_of(@group)
User.followees_of(@group)

@group.all_followers
@user.all_followees

Getting a model’s followers/followees by type is also possible:

@group.followers_by_type("user")
@user.followees_by_type("group")

And their count:

@group.followers_by_type("user")
@group.followers_count_by_type("user")
@user.followees_by_type("group")
@user.followees_count_by_type("group")

You can also get a model’s follow/followed history:

@user.ever_follow
@group.ever_followed

Another feature is to get a list of models which has the most followers/followees:

User.with_max_followees
User.with_min_followees
User.with_max_followees_by_type('group')
User.with_min_followees_by_type('group')
Group.with_max_followers
Group.with_min_followers
Group.with_max_followers_by_type('user')
Group.with_min_followers_by_type('user')

Now you can tell if two models have some common followers/followees by following methods:

@user.common_followees?(@another_user)
@user.common_followers?(@group)

And see what the common followers/followees are:

@user.common_followees_with(@another_user)
@user.common_followers_with(@group)
  • Any bug or issue, please send me an email: ustc.flyingfox@gmail.com

TODO¶ ↑

  • inter-models followable #FINISHED#

  • divide into two parts: followable(being followed) and follower(following others) #FINISHED#

  • following history/followed history #FINISHED#

  • most/least followed/following #FINISHED

  • add authorization to followable models #FINISHED#

  • common followers/followees #FINISHED#

  • add support for mongo_mapper in next version

!!If you have any advice, plese do not hesitate to tell me!!

Thanks¶ ↑

Thanks the author(s) of acts_as_followable, you can find this gem here

Copyright © Jie Fan. See LICENSE.txt for further details.