An active record follow system developed using ruby on rails applying domain driven design and test driven development principles.
For rails 4 support use branch v0.0.7-stable.
For rails 5 support use branch v0.1.1-stable.
This gem is heavily influenced by cmer/socialization.
Add this line to your application's Gemfile:
gem 'follow_system'
And then execute:
$ bundle
Or install it yourself as:
$ gem install follow_system
$ rails g follow_system
Let's suppose for a moment that you have a celebrity news application and a User can follow a Celebrity or several Celebrity models. The user model becomes the follower and the celebrity model becomes the followee.
class Celebrity < ActiveRecord::Base
act_as_followee
validates :name, { presence: true, uniqueness: true }
end
class User < ActiveRecord::Base
act_as_follower
validates :username, { presence: true, uniqueness: true }
end
celebrity.is_followee? # returns true
celebrity.followed_by?(user) # returns true if user follows the celebrity object, false otherwise
celebrity.followers_by(User) # returns a scope of FollowSystem::Follow join model that belongs to the celebrity object and belongs to follower objects of type User
user.is_follower? # returns true
user.follow(celebrity) # Creates an instance of FollowSystem::Follow join model associating the user object and the celebrity object, returns true if succeded, false otherwise
user.unfollow(celebrity) # Destroys an instance of FollowSystem::Follow join model that associates the user object and the celebrity object, returns true if succeded, false otherwise
user.toggle_follow(celebrity) # Follows / unfollows the celebrity
user.follows?(celebrity) # returns true if the user object follows the celebrity object, false otherwise
user.followees_by(Celebrity) # returns a scope of FollowSystem::Follow join model that belongs to the user object and belongs to followee objects of type Celebrity
For more information read the api documentation.
- Fork it ( https://github.com/pmviva/follow_system/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request