
Security News
New Website “Is It Really FOSS?” Tracks Transparency in Open Source Distribution Models
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
activerecord-reputation-system
Advanced tools
The 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:
If you are updating to version 2 from version older, you should check out migration guide.
For Rails 3 use versions 2.0.2 and older.
Add to Gemfile:
gem 'activerecord-reputation-system'
Run:
bundle install
rails generate reputation_system
rake db:migrate
Let's say we want to keep track of user karma in Q&A 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:
class User < ActiveRecord::Base
has_many :answers
has_many :questions
has_reputation :karma,
:source => [
{ :reputation => :questioning_skill, :weight => 0.8 },
{ :reputation => :answering_skill }]
has_reputation :questioning_skill,
:source => { :reputation => :votes, :of => :questions }
has_reputation :answering_skill,
:source => { :reputation => :avg_rating, :of => :answers }
end
class Answer < ActiveRecord::Base
belongs_to :user, :as => :author
has_reputation :avg_rating,
:source => :user,
:aggregated_by => :average,
:source_of => [{ :reputation => :answering_skill, :of => :author }]
end
class Question < ActiveRecord::Base
belongs_to :user
has_reputation :votes,
:source => :user
end
Once reputation system is defined, evaluations for answers and questions can be added as follow:
@answer.add_evaluation(:avg_rating, 3, @user)
@question.add_evaluation(:votes, 1, @user)
Reputation value can be accessed as follow:
@answer.reputation_for(:avg_rating) #=> 3
@question.reputation_for(:votes) #=> 1
@user.reputation_for(:karma)
You can query for records using reputation value:
User.find_with_reputation(:karma, :all, { :condition => 'karma > 10' })
You can get source records that have evaluated the target record:
@question.evaluators_for(:votes) #=> [@user]
You can get target records that have been evaluated by a given source record:
Question.evaluated_by(:votes, @user) #=> [@question]
You can use a custom aggregation function, which is a feature available on this fork, but not on the original implementation. You just need to provide the name of the method on the :aggregated_by option, and implement this method on the model. On the example below, our aggregation function sums all values and multiply by ten:
class Answer < ActiveRecord::Base
belongs_to :author, :class_name => 'User'
belongs_to :question
has_reputation :custom_rating,
:source => :user,
:aggregated_by => :custom_aggregation
def custom_aggregation(*args)
rep, source, weight = args[0..2]
# Ruby doesn't support method overloading, so let's handle parameters on a condition
# For a new source, these are the input parameters:
# rep, source, weight
if args.length === 3
rep.value + weight * source.value * 10
# For an updated source, these are the input parameters:
# rep, source, weight, oldValue, newSize
elsif args.length === 5
oldValue, newSize = args[3..4]
rep.value + (source.value - oldValue) * 10
end
end
end
Please refer Wiki for available APIs and more information.
Katsuya Noguchi
For transparency and insight into our release cycle, releases will be numbered with the follow format:
<major>.<minor>.<patch>
And constructed with the following guidelines:
For more information on semantic versioning, please visit http://semver.org/.
Copyright 2012 Twitter, Inc.
Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
FAQs
Unknown package
We found that activerecord-reputation-system demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.