0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
A very simple mongomapper plugin to add vote up/down superpowers to your models
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

= 1.3.0
~> 1.0.0
>= 0
~> 1.5.1
>= 0
~> 2.1.0
~> 0.6.0
 Project Readme

mm-voteable¶ ↑

A very simple mongomapper plugin to add vote up/down superpowers to your models.

v1.2 is a mongomapper 0.9.0 update to support the new plugin system if you are using mongomapper 0.8.x please use version 1.1 of the gem

Usage¶ ↑

Install the gem

gem install mm-voteable

Or add it to your Gemfile

gem 'mm-voteable'

Then add the voteable plugin to you MongoMapper::Document

class Post
  include MongoMapper::Document
  plugin MongoMapper::Plugins::Voteable

  def on_add_vote(vote)
    do something when a vote is added...
  end
end

You must implement the on_add_vote callback! - It can be an empty implementation, but I use it to create ActivityStream Items after someone votes on a NewsArticle

@post = Post.create
@voter = User.create

@post.add_vote!(1, @user)
@post.add_vote!(1, @user)

@post.votes_count #=> 2
@posts.votes #=> [<Vote>]
@posts.voters #=> [<User>]
@posts.voters.include?(@voter) #=> true

Limitations¶ ↑

I made this plugin for voting up and down on articles (kind of like stack overflow) so there are currently some limitations

  • the vote value can only be one of 1 or -1

  • the voteable model has a ‘user’ belongs_to association

  • a user can only vote once on a voteable item

  • the owner of a voteable item, cannot vote

Feel free to code any of these limitations out and send me a patch, this is just how I have used it so far

Contributing to mm-voteable¶ ↑

  • Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet

  • Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it

  • Fork the project

  • Start a feature/bugfix branch

  • Commit and push until you are happy with your contribution

  • Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright © 2010 Luke Cunningham. See LICENSE.txt for further details.