Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 134 lines (93 sloc) 4.318 kb
5454af5 Change Active Record to ActiveRecord
Katsuya Noguchi authored
1 ## ActiveRecord Reputation System [![Build Status](https://secure.travis-ci.org/twitter/activerecord-reputation-system.png)](http://travis-ci.org/twitter/activerecord-reputation-system) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/twitter/activerecord-reputation-system)
f9f904d Initial commit
Katsuya Noguchi authored
2
a05ad36 Update summary
Katsuya Noguchi authored
3 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:
4 * define reputations in easily readable way.
5 * integrate reputation systems into applications and decouple the system from the main application.
6 * discover more about your application and make better decisions.
f9f904d Initial commit
Katsuya Noguchi authored
7
8 ## Installation
9
ae9a482 Update README for version 2.0.0
Katsuya Noguchi authored
10 * 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).
11
94a8373 @NARKOZ update installation instructions
NARKOZ authored
12 Add to Gemfile:
13
14 ```ruby
314a3f9 Add more example usages in README
Katsuya Noguchi authored
15 gem 'activerecord-reputation-system'
94a8373 @NARKOZ update installation instructions
NARKOZ authored
16 ```
17
18 Run:
19
20 ```ruby
21 bundle install
49571aa Correct wrong command
Katsuya Noguchi authored
22 rails generate reputation_system
94a8373 @NARKOZ update installation instructions
NARKOZ authored
23 rake db:migrate
24 ```
f9f904d Initial commit
Katsuya Noguchi authored
25
5136972 Fix a bug associated with race condition
Katsuya Noguchi authored
26 * Please do the installation on every upgrade as it may include new migration files.
27
ca91846 Arrange section order in README
Katsuya Noguchi authored
28 ## Quick Start
f9f904d Initial commit
Katsuya Noguchi authored
29
30 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:
31 ```ruby
32 class User < ActiveRecord::Base
33 has_many :answers
34 has_many :questions
35
36 has_reputation :karma,
37 :source => [
38 { :reputation => :questioning_skill, :weight => 0.8 },
314a3f9 Add more example usages in README
Katsuya Noguchi authored
39 { :reputation => :answering_skill }]
f9f904d Initial commit
Katsuya Noguchi authored
40
41 has_reputation :questioning_skill,
314a3f9 Add more example usages in README
Katsuya Noguchi authored
42 :source => { :reputation => :votes, :of => :questions }
f9f904d Initial commit
Katsuya Noguchi authored
43
44 has_reputation :answering_skill,
314a3f9 Add more example usages in README
Katsuya Noguchi authored
45 :source => { :reputation => :avg_rating, :of => :answers }
f9f904d Initial commit
Katsuya Noguchi authored
46 end
47
48 class Answer < ActiveRecord::Base
49 belongs_to :user, :as => :author
50
51 has_reputation :avg_rating,
52 :source => :user,
53 :aggregated_by => :average,
54 :source_of => [{ :reputation => :answering_skill, :of => :author }]
55 end
56
57
58 class Question < ActiveRecord::Base
59 belongs_to :user
60
61 has_reputation :votes,
314a3f9 Add more example usages in README
Katsuya Noguchi authored
62 :source => :user
f9f904d Initial commit
Katsuya Noguchi authored
63 end
64 ```
65
66 Once reputation system is defined, evaluations for answers and questions can be added as follow:
67 ```ruby
68 @answer.add_evaluation(:avg_rating, 3, @user)
69 @question.add_evaluation(:votes, 1, @user)
70 ```
71
72 Reputation value can be accessed as follow:
73 ```ruby
97aa18d Fix typos.
Katsuya Noguchi authored
74 @answer.reputation_for(:avg_rating) #=> 3
75 @question.reputation_for(:votes) #=> 1
76 @user.reputation_for(:karma)
f9f904d Initial commit
Katsuya Noguchi authored
77 ```
78
314a3f9 Add more example usages in README
Katsuya Noguchi authored
79 You can query for records using reputation value:
80 ```ruby
bae5e03 Update README.md
Katsuya Noguchi authored
81 User.find_with_reputation(:karma, :all, { :condition => 'karma > 10' })
314a3f9 Add more example usages in README
Katsuya Noguchi authored
82 ```
83
84 You can get source records that have evaluated the target record:
85 ```ruby
86 @question.evaluators_for(:votes) #=> [@user]
87 ```
88
89 You can get target records that have been evaluated by a given source record:
90 ```ruby
91 Question.evaluated_by(:votes, @user) #=> [@question]
92 ```
93
3182792 Update README
Katsuya Noguchi authored
94 ## Documentation
f9f904d Initial commit
Katsuya Noguchi authored
95
6367c9f Update README.md
Katsuya Noguchi authored
96 Please refer [Wiki](https://github.com/twitter/activerecord-reputation-system/wiki) for available APIs and more information.
f9f904d Initial commit
Katsuya Noguchi authored
97
98 ## Authors
99
ae9a482 Update README for version 2.0.0
Katsuya Noguchi authored
100 Katsuya Noguchi
101 * [http://twitter.com/kn](http://twitter.com/kn)
f3cc872 Update author's Github username.
Katsuya Noguchi authored
102 * [http://github.com/kn](http://github.com/kn)
f9f904d Initial commit
Katsuya Noguchi authored
103
6e4bc8d Add Contributors section in README
Katsuya Noguchi authored
104 ## Contributors
105
106 1. [NARKOZ (Nihad Abbasov)](https://github.com/NARKOZ) - 4 commits
107 2. [elitheeli (Eli Fox-Epstein)](https://github.com/elitheeli) - 1 commit
108 3. [amrnt (Amr Tamimi)](https://github.com/amrnt) - 1 commit
109
f0ed802 Add a link to RailsCasts
Katsuya Noguchi authored
110 ## Related Links
111
112 * RailsCasts: http://railscasts.com/episodes/364-active-record-reputation-system
ae9a482 Update README for version 2.0.0
Katsuya Noguchi authored
113 * Inspired by ["Building Web Reputation Systems" by Randy Farmer and Bryce Glass](http://shop.oreilly.com/product/9780596159801.do)
f0ed802 Add a link to RailsCasts
Katsuya Noguchi authored
114
ca91846 Arrange section order in README
Katsuya Noguchi authored
115 ## Versioning
116
117 For transparency and insight into our release cycle, releases will be numbered with the follow format:
118
119 `<major>.<minor>.<patch>`
120
121 And constructed with the following guidelines:
122
123 * Breaking backwards compatibility bumps the major
124 * New additions without breaking backwards compatibility bumps the minor
125 * Bug fixes and misc changes bump the patch
126
127 For more information on semantic versioning, please visit http://semver.org/.
128
f9f904d Initial commit
Katsuya Noguchi authored
129 ## License
130
131 Copyright 2012 Twitter, Inc.
132
133 Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
Something went wrong with that request. Please try again.