{"id":13484355,"url":"https://github.com/tcocca/acts_as_follower","last_synced_at":"2025-03-27T16:30:45.419Z","repository":{"id":554741,"uuid":"62213","full_name":"tcocca/acts_as_follower","owner":"tcocca","description":"A Gem to add Follow functionality for models","archived":false,"fork":false,"pushed_at":"2024-05-01T19:09:48.000Z","size":140,"stargazers_count":865,"open_issues_count":56,"forks_count":197,"subscribers_count":32,"default_branch":"master","last_synced_at":"2025-03-19T06:17:46.452Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tcocca.png","metadata":{"files":{"readme":"README.rdoc","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2008-10-12T20:51:06.000Z","updated_at":"2025-02-08T12:42:18.000Z","dependencies_parsed_at":"2024-06-18T14:07:16.776Z","dependency_job_id":null,"html_url":"https://github.com/tcocca/acts_as_follower","commit_stats":{"total_commits":115,"total_committers":17,"mean_commits":6.764705882352941,"dds":0.5913043478260869,"last_synced_commit":"c5ac7b9601c4af01eb4d9112330b27be4d694ecc"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tcocca%2Facts_as_follower","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tcocca%2Facts_as_follower/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tcocca%2Facts_as_follower/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tcocca%2Facts_as_follower/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tcocca","download_url":"https://codeload.github.com/tcocca/acts_as_follower/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245882227,"owners_count":20687854,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T17:01:22.977Z","updated_at":"2025-03-27T16:30:43.204Z","avatar_url":"https://github.com/tcocca.png","language":"Ruby","funding_links":[],"categories":["Ruby","ORM/ODM Extensions"],"sub_categories":[],"readme":"= acts_as_follower\n\nacts_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.\n\nMain uses would be for Users to follow other Users or for Users to follow Books, etc...\n\n(Basically, to develop the type of follow system that GitHub has)\n\n{\u003cimg src=\"https://travis-ci.org/tcocca/acts_as_follower.png\" /\u003e}[https://travis-ci.org/tcocca/acts_as_follower]\n\n\n== Installation\n\n=== The master branch supports Rails 5\n\nAdd the gem to the gemfile:\n  gem 'acts_as_follower', github: 'tcocca/acts_as_follower', branch: 'master'\n\nOther instructions same as for Rails 4.\n\n=== Rails 4.x support\n\nThe first release that support Rails 4 is 0.2.0\n\nAdd the gem to the gemfile:\n  gem \"acts_as_follower\"\n\nRun the generator:\n  rails generate acts_as_follower\n\nThis will generate a migration file as well as a model called Follow.\n\n=== Rails 3.x support\n\nRails 3 is supports in the rails_3 branch https://github.com/tcocca/acts_as_follower/tree/rails_3\nThe last gem release for Rails 3 support was 0.1.1, so install the gem using ~\u003e 0.1.1\n\nAdd the gem to the gemfile:\n  gem \"acts_as_follower\", '~\u003e 0.1.1'\n\nor install from the branch\n\n  gem \"acts_as_follower\", git: 'git://github.com/tcocca/acts_as_follower.git', branch: 'rails_3'\n\nRun the generator:\n  rails generate acts_as_follower\n\nThis will generate a migration file as well as a model called Follow.\n\n=== Rails 2.3.x support\n\nRails 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.\nThe gem version does not work with rails 2.3.x.\n\nRun the following command:\n  script/plugin install git://github.com/tcocca/acts_as_follower.git -r rails_2.3.x\n\nRun the generator:\n  script/generate acts_as_follower\n\n\n== Usage\n\n=== Setup\n\nMake your model(s) that you want to allow to be followed acts_as_followable, just add the mixin:\n  class User \u003c ActiveRecord::Base\n    ...\n    acts_as_followable\n    ...\n  end\n\n  class Book \u003c ActiveRecord::Base\n    ...\n    acts_as_followable\n    ...\n  end\n\nMake your model(s) that can follow other models acts_as_follower\n  class User \u003c ActiveRecord::Base\n    ...\n    acts_as_follower\n    ...\n  end\n\n---\n\n=== acts_as_follower methods\n\nTo have an object start following another use the following:\n  book = Book.find(1)\n  user = User.find(1)\n  user.follow(book) # Creates a record for the user as the follower and the book as the followable\n\nTo stop following an object use the following\n  user.stop_following(book) # Deletes that record in the Follow table\n\nYou can check to see if an object that acts_as_follower is following another object through the following:\n  user.following?(book) # Returns true or false\n\nTo get the total number (count) of follows for a user use the following on a model that acts_as_follower\n  user.follow_count # Returns an integer\n\nTo get follow records that have not been blocked use the following\n  user.all_follows # returns an array of Follow records\n\nTo get all of the records that an object is following that have not been blocked use the following\n  user.all_following\n  # Returns an array of every followed object for the user, this can be a collection of different object types, eg: User, Book\n\nTo get all Follow records by a certain type use the following\n  user.follows_by_type('Book') # returns an array of Follow objects where the followable_type is 'Book'\n\nTo get all followed objects by a certain type use the following.\n  user.following_by_type('Book') # Returns an array of all followed objects for user where followable_type is 'Book', this can be a collection of different object types, eg: User, Book\n\nThere is also a method_missing to accomplish the exact same thing a following_by_type('Book') to make you life easier\n  user.following_users # exact same results as user.following_by_type('User')\n\nTo get the count of all Follow records by a certain type use the following\n  user.following_by_type_count('Book') # Returns the sql count of the number of followed books by that user\n\nThere is also a method_missing to get the count by type\n  user.following_books_count # Calls the user.following_by_type_count('Book') method\n\nThere is now a method that will just return the Arel scope for follows so that you can chain anything else you want onto it:\n  book.follows_scoped\nThis does not return the actual follows, just the scope of followings including the followables, essentially:  book.follows.unblocked.includes(:followable)\n\nThe following methods take an optional hash parameter of ActiveRecord options (:limit, :order, etc...)\n  follows_by_type, all_follows, all_following, following_by_type\n---\n\n=== acts_as_followable methods\n\nTo get all the followers of a model that acts_as_followable\n  book.followers  # Returns an array of all the followers for that book, a collection of different object types (eg. type User or type Book)\n\nThere is also a method that will just return the Arel scope for followers so that you can chain anything else you want onto it:\n  book.followers_scoped\nThis does not return the actual followers, just the scope of followings including the followers, essentially:  book.followings.includes(:follower)\n\nTo get just the number of follows use\n  book.followers_count\n\nTo get the followers of a certain type, eg: all followers of type 'User'\n  book.followers_by_type('User') # Returns an array of the user followers\n\nThere is also a method_missing for this to make it easier:\n  book.user_followers # Calls followers_by_type('User')\n\nTo get just the sql count of the number of followers of a certain type use the following\n  book.followers_by_type_count('User') # Return the count on the number of followers of type 'User'\n\nAgain, there is a method_missing for this method as well\n  book.count_user_followers # Calls followers_by_type_count('User')\n\nTo see is a model that acts_as_followable is followed by a model that acts_as_follower use the following\n  book.followed_by?(user)\n\n  # Returns true if the current instance is followed by the passed record\n  # Returns false if the current instance is blocked by the passed record or no follow is found\n\nTo block a follower call the following\n  book.block(user)\n  # Blocks the user from appearing in the followers list, and blocks the book from appearing in the user.all_follows or user.all_following lists\n\nTo unblock is just as simple\n  book.unblock(user)\n\nTo get all blocked records\n  book.blocks # Returns an array of blocked follower records (only unblocked) (eg. type User or type Book)\n\nIf you only need the number of blocks use the count method provided\n  book.blocked_followers_count\n\nUnblocking deletes all records of that follow, instead of just the :blocked attribute =\u003e false the follow is deleted.  So, a user would need to try and follow the book again.\nI would like to hear thoughts on this, I may change this to make the follow as blocked: false instead of deleting the record.\n\nThe following methods take an optional hash parameter of ActiveRecord options (:limit, :order, etc...)\n  followers_by_type, followers, blocks\n---\n\n=== Follow Model\n\nThe Follow model has a set of named_scope's.  In case you want to interface directly with the Follow model you can use them.\n  Follow.unblocked # returns all \"unblocked\" follow records\n\n  Follow.blocked # returns all \"blocked\" follow records\n\n  Follow.descending # returns all records in a descending order based on created_at datetime\n\nThis method pulls all records created after a certain date.  The default is 2 weeks but it takes an optional parameter.\n  Follow.recent\n  Follow.recent(4.weeks.ago)\n\nFollow.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.\n  Follow.for_follower(user)\nIf you don't need the blocked records just use the methods provided for this:\n  user.all_follows\n  # or\n  user.all_following\n\nFollow.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.\n  Follow.for_followable(book)\nAgain, if you don't need the blocked records use the method provided for this:\n  book.followers\nIf you need blocked records only\n  book.blocks\n\n\n== Comments/Requests\n\nIf anyone has comments or questions please let me know (tom dot cocca at gmail dot com).\nIf you have updates or patches or want to contribute I would love to see what you have or want to add.\n\n\n== Note on Patches/Pull Requests\n\n* Fork the project.\n* Make your feature addition or bug fix.\n* Add tests for it. This is important so I don't break it in a future version unintentionally (acts_as_follower uses Shoulda and Factory Girl)\n* Send me a pull request. Bonus points for topic branches.\n\n\n== Contributers\n\nThanks to everyone for their interest and time in committing to making this plugin better.\n\n* dougal (Douglas F Shearer) - https://github.com/dougal\n* jdg (Jonathan George) - https://github.com/jdg\n* m3talsmith (Michael Christenson II) - https://github.com/m3talsmith\n* joergbattermann (Jörg Battermann) - https://github.com/joergbattermann\n* TomK32 (Thomas R. Koll) - https://github.com/TomK32\n* drcapulet (Alex Coomans) - https://github.com/drcapulet\n* jhchabran (Jean Hadrien Chabran) - https://github.com/jhchabran\n* arthurgeek (Arthur Zapparoli) - https://github.com/arthurgeek\n* james2m (James McCarthy) - https://github.com/james2m\n* peterjm (Peter McCracken) - https://github.com/peterjm\n* merqlove (Alexander Merkulov) - https://github.com/merqlove\n\nPlease let me know if I missed you.\n\n\n== Copyright\n\nCopyright (c) 2008 - 2010 ( tom dot cocca at gmail dot com ), released under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftcocca%2Facts_as_follower","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftcocca%2Facts_as_follower","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftcocca%2Facts_as_follower/lists"}