Skip to content

An active record follow system developed using ruby on rails applying domain driven design and test driven development principles.

License

Notifications You must be signed in to change notification settings

pmviva/follow_system

Repository files navigation

FollowSystem

Build Status Gem Version Code Climate

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.

Installation

Add this line to your application's Gemfile:

gem 'follow_system'

And then execute:

$ bundle

Or install it yourself as:

$ gem install follow_system

Usage

Run the generator

$ 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.

Celebrity object

class Celebrity < ActiveRecord::Base
  act_as_followee

  validates :name, { presence: true, uniqueness: true }
end

User object

class User < ActiveRecord::Base
  act_as_follower

  validates :username, { presence: true, uniqueness: true }
end

Followee object methods

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

Follower object methods

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.

Contributing

  1. Fork it ( https://github.com/pmviva/follow_system/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

About

An active record follow system developed using ruby on rails applying domain driven design and test driven development principles.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages