https://github.com/brianp/dm-is-voteable
A DataMapper voting gem
https://github.com/brianp/dm-is-voteable
Last synced: 8 months ago
JSON representation
A DataMapper voting gem
- Host: GitHub
- URL: https://github.com/brianp/dm-is-voteable
- Owner: brianp
- License: mit
- Created: 2010-10-03T23:33:21.000Z (over 15 years ago)
- Default Branch: master
- Last Pushed: 2013-09-26T06:28:16.000Z (over 12 years ago)
- Last Synced: 2025-10-07T15:57:55.940Z (8 months ago)
- Language: Ruby
- Homepage:
- Size: 216 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG
- License: MIT-LICENSE
Awesome Lists containing this project
README
# dm-is-voteable
[](https://travis-ci.org/brianp/dm-is-voteable)
[](https://codeclimate.com/github/brianp/dm-is-voteable)
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.
```ruby
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:
```ruby
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:
```ruby
user_ip = request.env['REMOTE_ADDR']
model.vote(user_ip)
```