{"id":13476320,"url":"https://github.com/twitter/activerecord-reputation-system","last_synced_at":"2025-09-29T00:32:45.323Z","repository":{"id":3315030,"uuid":"4357713","full_name":"twitter/activerecord-reputation-system","owner":"twitter","description":"An Active Record Reputation System for Rails","archived":true,"fork":false,"pushed_at":"2016-01-14T23:40:36.000Z","size":745,"stargazers_count":1334,"open_issues_count":28,"forks_count":121,"subscribers_count":142,"default_branch":"master","last_synced_at":"2025-08-30T14:50:12.830Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/twitter.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-05-17T11:43:53.000Z","updated_at":"2025-07-08T16:16:55.000Z","dependencies_parsed_at":"2022-08-26T02:33:22.927Z","dependency_job_id":null,"html_url":"https://github.com/twitter/activerecord-reputation-system","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/twitter/activerecord-reputation-system","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twitter%2Factiverecord-reputation-system","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twitter%2Factiverecord-reputation-system/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twitter%2Factiverecord-reputation-system/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twitter%2Factiverecord-reputation-system/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/twitter","download_url":"https://codeload.github.com/twitter/activerecord-reputation-system/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twitter%2Factiverecord-reputation-system/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":277450939,"owners_count":25819971,"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","status":"online","status_checked_at":"2025-09-28T02:00:08.834Z","response_time":79,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-31T16:01:28.908Z","updated_at":"2025-09-29T00:32:45.074Z","avatar_url":"https://github.com/twitter.png","language":"Ruby","readme":"## ActiveRecord Reputation System  [![Build Status](https://travis-ci.org/twitter/activerecord-reputation-system.svg?branch=master)](https://travis-ci.org/twitter/activerecord-reputation-system) [![Code Climate](https://codeclimate.com/github/twitter/activerecord-reputation-system/badges/gpa.svg)](https://codeclimate.com/github/twitter/activerecord-reputation-system)\n\nThe Active Record Reputation System helps you build the reputation system for your Rails application. It allows Active Record to have reputations and get evaluated by other records. This gem allows you to:\n* define reputations in easily readable way.\n* integrate reputation systems into applications and decouple the system from the main application.\n* discover more about your application and make better decisions.\n\n## Installation\n\n* If you are updating to version 2 from version older, you should check out [migration guide](https://github.com/twitter/activerecord-reputation-system/wiki/Migrate-to-Version-2.0).\n\n* **For Rails 3 use versions 2.0.2 and older.**\n\nAdd to Gemfile:\n\n```ruby\ngem 'activerecord-reputation-system'\n```\n\nRun:\n\n```ruby\nbundle install\nrails generate reputation_system\nrake db:migrate\n```\n\n* Please do the installation on every upgrade as it may include new migration files.\n\n## Quick Start \n\nLet's say we want to keep track of user karma in Q\u0026A site where user karma is sum of questioning skill and answering skill. Questioning skill is sum of votes for user's questions and Answering skill is sum of average rating of user's answers. This can be defined as follow:\n```ruby\nclass User \u003c ActiveRecord::Base\n  has_many :answers\n  has_many :questions\n\n  has_reputation :karma,\n      :source =\u003e [\n          { :reputation =\u003e :questioning_skill, :weight =\u003e 0.8 },\n          { :reputation =\u003e :answering_skill }]\n\n  has_reputation :questioning_skill,\n      :source =\u003e { :reputation =\u003e :votes, :of =\u003e :questions }\n\n  has_reputation :answering_skill,\n      :source =\u003e { :reputation =\u003e :avg_rating, :of =\u003e :answers }\nend\n\nclass Answer \u003c ActiveRecord::Base\n  belongs_to :user, :as =\u003e :author\n\n  has_reputation :avg_rating,\n      :source =\u003e :user,\n      :aggregated_by =\u003e :average,\n      :source_of =\u003e [{ :reputation =\u003e :answering_skill, :of =\u003e :author }]\nend\n\n\nclass Question \u003c ActiveRecord::Base\n  belongs_to :user\n\n  has_reputation :votes,\n      :source =\u003e :user\nend\n```\n\nOnce reputation system is defined, evaluations for answers and questions can be added as follow:\n```ruby\n@answer.add_evaluation(:avg_rating, 3, @user)\n@question.add_evaluation(:votes, 1, @user)\n```\n\nReputation value can be accessed as follow:\n```ruby\n@answer.reputation_for(:avg_rating) #=\u003e 3\n@question.reputation_for(:votes) #=\u003e 1\n@user.reputation_for(:karma)\n```\n\nYou can query for records using reputation value:\n```ruby\nUser.find_with_reputation(:karma, :all, { :condition =\u003e 'karma \u003e 10' })\n```\n\nYou can get source records that have evaluated the target record:\n```ruby\n@question.evaluators_for(:votes) #=\u003e [@user]\n```\n\nYou can get target records that have been evaluated by a given source record:\n```ruby\nQuestion.evaluated_by(:votes, @user) #=\u003e [@question]\n```\n\nTo use a custom aggregation function you need to provide the name of the method\non the `:aggregated_by option`, and implement this method on the model.\nOn the example below, our aggregation function sums all values and multiply by ten:\n```ruby\nclass Answer \u003c ActiveRecord::Base\n  belongs_to :author, :class_name =\u003e 'User'\n  belongs_to :question\n\n  has_reputation :custom_rating,\n    :source =\u003e :user,\n    :aggregated_by =\u003e :custom_aggregation\n\n  def custom_aggregation(*args)\n    rep, source, weight = args[0..2]\n\n    # Ruby doesn't support method overloading, so let's handle parameters on a condition\n\n    # For a new source, these are the input parameters:\n    # rep, source, weight\n    if args.length == 3\n      rep.value + weight * source.value * 10\n\n    # For an updated source, these are the input parameters:\n    # rep, source, weight, oldValue, newSize\n    elsif args.length == 5\n      oldValue, newSize = args[3..4]\n      rep.value + (source.value - oldValue) * 10\n    end\n  end\nend\n```\n\n## Documentation\n\nPlease refer [Wiki](https://github.com/twitter/activerecord-reputation-system/wiki) for available APIs and more information.\n\n## Authors\n\nKatsuya Noguchi\n* [http://twitter.com/kn](http://twitter.com/kn)\n* [http://github.com/kn](http://github.com/kn)\n\n## Related Links\n\n* RailsCasts: http://railscasts.com/episodes/364-active-record-reputation-system\n* Inspired by [\"Building Web Reputation Systems\" by Randy Farmer and Bryce Glass](http://shop.oreilly.com/product/9780596159801.do)\n\n## Versioning\n\nFor transparency and insight into our release cycle, releases will be numbered with the follow format:\n\n`\u003cmajor\u003e.\u003cminor\u003e.\u003cpatch\u003e`\n\nAnd constructed with the following guidelines:\n\n* Breaking backwards compatibility bumps the major\n* New additions without breaking backwards compatibility bumps the minor\n* Bug fixes and misc changes bump the patch\n\nFor more information on semantic versioning, please visit http://semver.org/.\n\n## License\n\nCopyright 2012 Twitter, Inc.\n\nLicensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0\n","funding_links":[],"categories":["Ruby","ORM/ODM Extensions","1. language"],"sub_categories":["1.1 ruby"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwitter%2Factiverecord-reputation-system","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwitter%2Factiverecord-reputation-system","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwitter%2Factiverecord-reputation-system/lists"}