README.rdoc in voteable_mongo-0.8.1 vs README.rdoc in voteable_mongo-0.9.0

- old
+ new

@@ -1,8 +1,8 @@ = Voteable Mongo -voteable_mongo allows you to make your Mongoid::Document (mongo_mapper support coming soon) objects voteable (up or down) and tabulate votes count and votes point for you. For instance, in a forum, a user can vote up (or down) on a post or a comment. +voteable_mongo allows you to make your Mongoid::Document or MongoMapper::Document objects voteable (up or down) and tabulate votes count and votes point for you. For instance, in a forum, a user can vote up (or down) on a post or a comment. voteable_mongo is built for speed. It uses only one database request per collection to validate data, update data, and get updated data. Initial idea is based on http://cookbook.mongodb.org/patterns/votes Sample app at https://github.com/vinova/simple_qa @@ -25,10 +25,11 @@ == Usage === Make Post and Comment voteable, User become the voter +== Mongoid post.rb class Post include Mongoid::Document include Mongo::Voteable @@ -60,10 +61,46 @@ class User include Mongoid::Document include Mongo::Voter end + +== MongoMapper +post.rb + + class Post + include MongoMapper::Document + include Mongo::Voteable + + # set points for each vote + voteable self, :up => +1, :down => -1 + + many :comments + end + +comment.rb + + require 'post' + + class Comment + include MongoMapper::Document + include Mongo::Voteable + + belongs_to :post + + voteable self, :up => +1, :down => -3 + voteable Post, :up => +2, :down => -1 + end + +user.rb + + class User + include MongoMapper::Document + include Mongo::Voter + end + + === Make a vote @user.vote(@post, :up) Is equivalent to @@ -87,12 +124,11 @@ Re-vote Post.vote(:voter_id => user_id, :votee_id => post_id, :value => :up, :revote => true) Un-vote Post.vote(:voter_id => user_id, :votee_id => post_id, :value => :up, :unvote => true) - -In-case you need updated voteable object, add :return_votee => true - votee = Post.vote(:voter_id => user_id, :votee_id => post_id, :value => :up, :return_votee => true) + +Note: vote function always return updated votee object === Get vote_value @user.vote_value(@post) @user.vote_value(:class_type => 'Post', :votee_id => post_id)