Skip to content

brianp/dm-is-voteable

Repository files navigation

dm-is-voteable

Build Status Code Climate

A DataMapper compatible voting gem. Can track votes by identifier so a user may only submit a single vote.

Requirments

  • Ruby 1.9

Installation

To install as a gem add the following line to your gem file. gem 'dm-is-voteable'

Then: bundle install

And build the required DB tables: rake db:auto_update

Example

Add is_voteable To any model and gain the power of the vote method.

class Movie
  include DataMapper::Resource

  property :id, Serial
  property :title, String, required: true
  
  is_voteable
end

Vote for the Model by calling model.vote

Voting Restrictions

Allow only a single vote per user within a certain time frame by setting a time frame in the model:

class Movie
  include DataMapper::Resource

  property :id, Serial
  property :title, String, required: true
  
  is_voteable(last_vote_time: ->{ 3.days.ago })
end

Then send an identifier along with the vote:

user_ip = request.env['REMOTE_ADDR']
model.vote(user_ip)

About

A DataMapper voting gem

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages