rails_rest_vote 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +129 -0
- data/Rakefile +2 -0
- data/app/controllers/rails_rest_vote/api/votes_controller.rb +157 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/config/routes.rb +13 -0
- data/lib/generators/rails_rest_vote/rails_rest_vote_generator.rb +76 -0
- data/lib/generators/rails_rest_vote/templates/migration.rb +12 -0
- data/lib/rails_rest_vote.rb +18 -0
- data/lib/rails_rest_vote/engine.rb +14 -0
- data/lib/rails_rest_vote/version.rb +3 -0
- data/rails_rest_vote.gemspec +27 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9814a411ccc447f6cf372b2bfa307866f6c289be
|
4
|
+
data.tar.gz: b01bf982e1da607387bcd731a4957178d46c8302
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3eba662bc0ebc434f8b05ad289b221a988c9ecf803c3c533eafd85e811a03bab0480d2d1b6e603f523069f726d2e13cf4ef89c83fc9eb51404e8cd55802ab7e7
|
7
|
+
data.tar.gz: a9ef13fef6979627e429b919e10d6bc50fca7bd77dbf0f518c29171a13e3fbbc29545f57327a52c4e4fc3cda39321b8b59440f9ab5306eff1d95ad37e7a51fb3
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at abhinav.sohani@consultadd.in. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 abhinav
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
# RailsRestVote
|
2
|
+
|
3
|
+
Rails Rest Vote is a Ruby Gem which can add voting feature to any model of your rails application and exposes its RESTful APIs.
|
4
|
+
|
5
|
+
If you are using any frontend framework like angular2 in your application it is really helpful.
|
6
|
+
|
7
|
+
>**DISCLAIMER**
|
8
|
+
>
|
9
|
+
>Your application user managment table name should be `user`, It is recommended to use [devise gem](https://github.com/plataformatec/devise) for authentication purpose.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'rails_rest_vote'
|
17
|
+
```
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle install
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install rails_rest_vote
|
25
|
+
|
26
|
+
#### Database Migrations
|
27
|
+
|
28
|
+
Run below command in your project folder from terminal.
|
29
|
+
|
30
|
+
$ rails g rails_rest_vote user
|
31
|
+
|
32
|
+
It will do three things for you.
|
33
|
+
|
34
|
+
- Create a migration file of Vote table in db/migrate/ folder.
|
35
|
+
- Insert association in user model i.e has_many :votes
|
36
|
+
- Create vote model i.e app/models/vote.rb
|
37
|
+
|
38
|
+
After that migrate database by using.
|
39
|
+
|
40
|
+
$ rake db:migrate
|
41
|
+
|
42
|
+
Now you are ready to go.
|
43
|
+
|
44
|
+
## Usage
|
45
|
+
|
46
|
+
Add below line to the model you want to vote or like on
|
47
|
+
|
48
|
+
has_many :votes, :as => :votable
|
49
|
+
|
50
|
+
It can be used in two different ways.
|
51
|
+
|
52
|
+
1. Use as two buttons one for upvote and other for downvote as in _stackoverflow_.
|
53
|
+
|
54
|
+
##### APIs
|
55
|
+
|
56
|
+
> /api/votes/up
|
57
|
+
|
58
|
+
Api is used for upvote on model. user must be signed in for upvoting.
|
59
|
+
```
|
60
|
+
method: POST
|
61
|
+
body: {"votable_id":"1","votable_type":"Service"}
|
62
|
+
content-type: application/json
|
63
|
+
response: {"status":200,"message":"upvoted successfully."}
|
64
|
+
```
|
65
|
+
|
66
|
+
> /api/votes/down
|
67
|
+
|
68
|
+
Api is used for downvote on model. user must be signed in for downvoting.
|
69
|
+
```
|
70
|
+
method: POST
|
71
|
+
body: {"votable_id":"1","votable_type":"Service"}
|
72
|
+
content-type: application/json
|
73
|
+
response: {"status":200,"message":"downvoted successfully."}
|
74
|
+
```
|
75
|
+
> /api/votes/user?user_id=1
|
76
|
+
|
77
|
+
Api returns upvote and downvote count done by a particular user.
|
78
|
+
```
|
79
|
+
method: GET
|
80
|
+
content-type: application/json
|
81
|
+
response: {"status":200,"upcount":1,"upvotes":[{"id":1,...}], "downcount":1,"downvotes":[{"id":3,...}]}
|
82
|
+
```
|
83
|
+
> /api/votes/model?votable_id=1&votable_type=Service
|
84
|
+
|
85
|
+
Api returns upvote and downvote count done on a particular model.
|
86
|
+
```
|
87
|
+
method: GET
|
88
|
+
content-type: application/json
|
89
|
+
response: {"status":200,"upcount":1,"upvotes":[{"id":1,...}], "downcount":1,"downvotes":[{"id":3,...}]}
|
90
|
+
```
|
91
|
+
|
92
|
+
2. Use as one button used for like/unlike just like _facebook_.
|
93
|
+
|
94
|
+
##### APIs
|
95
|
+
|
96
|
+
> /api/likes
|
97
|
+
|
98
|
+
Api is used for like. user must be signed in for liking.
|
99
|
+
```
|
100
|
+
method: POST
|
101
|
+
body: {"votable_id":"1","votable_type":"Service"}
|
102
|
+
content-type: application/json
|
103
|
+
response: {"status":200,"message":"liked successfully."}
|
104
|
+
```
|
105
|
+
> /api/likes/user?user_id=1
|
106
|
+
|
107
|
+
Api returns like count done by a particular user.
|
108
|
+
```
|
109
|
+
method: GET
|
110
|
+
content-type: application/json
|
111
|
+
response: {"status":200,"likecount":1,"likes":[{"id":1,...}]}
|
112
|
+
```
|
113
|
+
> /api/likes/model?votable_id=1&votable_type=Service
|
114
|
+
|
115
|
+
Api returns like count done on a particular model.
|
116
|
+
```
|
117
|
+
method: GET
|
118
|
+
content-type: application/json
|
119
|
+
response: {"status":200,"likecount":1,"likes":[{"id":1,...}]}
|
120
|
+
```
|
121
|
+
|
122
|
+
## Contributing
|
123
|
+
|
124
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/tixdo/rails_rest_vote. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
125
|
+
|
126
|
+
|
127
|
+
## License
|
128
|
+
|
129
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
require "json"
|
2
|
+
|
3
|
+
module RailsRestVote
|
4
|
+
class Api::VotesController < ApplicationController
|
5
|
+
#No record found exception handled
|
6
|
+
rescue_from ActiveRecord::RecordNotFound, with: :not_found
|
7
|
+
|
8
|
+
#This would turn off the CSRF check for json api posts/puts
|
9
|
+
skip_before_filter :verify_authenticity_token
|
10
|
+
|
11
|
+
#check current_user existance before voting actions
|
12
|
+
before_action :current_user?, :only=>[:up, :down , :like, :exists]
|
13
|
+
|
14
|
+
#check user already voted or not
|
15
|
+
before_action :exists?, :only=>[:up, :down, :like]
|
16
|
+
|
17
|
+
#intialize user
|
18
|
+
before_action :initialize_user, :only=>[:user_vote_count, :user_like_count]
|
19
|
+
|
20
|
+
#intialize votable object
|
21
|
+
before_action :initialize_votable_object, :only=>[:model_vote_count, :model_like_count]
|
22
|
+
|
23
|
+
|
24
|
+
#up vote is created form current user reference.
|
25
|
+
#vote value should be true.
|
26
|
+
#return success json i.e {"status":200,"message":"upvoted successfully."}
|
27
|
+
#
|
28
|
+
def up
|
29
|
+
upvote = current_user.votes.new(vote_params)
|
30
|
+
upvote.vote = true
|
31
|
+
send_post_response(upvote)
|
32
|
+
end
|
33
|
+
|
34
|
+
#down vote is created form current user reference.
|
35
|
+
#vote value should be false.
|
36
|
+
#return success json i.e {"status":200,"message":"downvoted successfully."}
|
37
|
+
#
|
38
|
+
def down
|
39
|
+
downvote = current_user.votes.new(vote_params)
|
40
|
+
downvote.vote = false
|
41
|
+
send_post_response(downvote)
|
42
|
+
end
|
43
|
+
|
44
|
+
#return vote up and down count of particular user.
|
45
|
+
#{"status":200,"upcount":1,"upvotes":[{"id":1,...}], "downcount":2,"downvotes":[{"id":3,...},{"id":2,...}]}
|
46
|
+
#
|
47
|
+
def user_vote_count
|
48
|
+
upvotes = @user.votes.where(:vote => true)
|
49
|
+
downvotes = @user.votes.where(:vote => false)
|
50
|
+
send_get_response(upvotes,downvotes)
|
51
|
+
end
|
52
|
+
|
53
|
+
#return vote up and down count on particular model.
|
54
|
+
#{"status":200,"upcount":1,"upvotes":[{"id":1,...}], "downcount":2,"downvotes":[{"id":3,...},{"id":2,...}]}
|
55
|
+
#
|
56
|
+
def model_vote_count
|
57
|
+
upvotes = @votable.votes.where(:vote => true)
|
58
|
+
downvotes = @votable.votes.where(:vote => false)
|
59
|
+
send_get_response(upvotes,downvotes)
|
60
|
+
end
|
61
|
+
|
62
|
+
#like and unlike feature handled from this method
|
63
|
+
#if record already present it just delete.
|
64
|
+
#response { status: :ok, message: "unliked successfully." })
|
65
|
+
#else response { status: :ok, message: "liked successfully." })
|
66
|
+
#
|
67
|
+
def like
|
68
|
+
like = current_user.votes.new(vote_params)
|
69
|
+
send_post_response(like)
|
70
|
+
end
|
71
|
+
|
72
|
+
#return like count of particular user.
|
73
|
+
#{"status":200,"likecount":1,"likes":[{"id":1,...}]}
|
74
|
+
#
|
75
|
+
def user_like_count
|
76
|
+
likes = @user.votes
|
77
|
+
send_like_response(likes)
|
78
|
+
end
|
79
|
+
|
80
|
+
#return like count on particular model.
|
81
|
+
#{"status":200,"likecount":1,"likes":[{"id":1,...}]}
|
82
|
+
#
|
83
|
+
def model_like_count
|
84
|
+
likes = @votable.votes
|
85
|
+
send_like_response(likes)
|
86
|
+
end
|
87
|
+
|
88
|
+
private
|
89
|
+
|
90
|
+
#check existance of record before creation
|
91
|
+
def exists?
|
92
|
+
initialize_votable_object
|
93
|
+
params[:vote][:votable_type] = params[:vote][:votable_type].capitalize
|
94
|
+
vote = params[:action] == "like" ? nil : params[:action] == "up" ? true : false
|
95
|
+
uservotes = current_user.votes.where("votable_id = ? AND votable_type = ? AND vote = ?",params[:vote][:votable_id],params[:vote][:votable_type],vote)
|
96
|
+
return uservotes.size > 0 ? voted(uservotes) : true
|
97
|
+
end
|
98
|
+
|
99
|
+
#intialize user object from params[:user_id]
|
100
|
+
def initialize_user
|
101
|
+
@user = User.find(params[:user_id])
|
102
|
+
end
|
103
|
+
|
104
|
+
#intialize votable object from params[:votable_id]
|
105
|
+
#constantize tries to find a declared constant with the name specified in the string
|
106
|
+
#
|
107
|
+
def initialize_votable_object
|
108
|
+
@votable = params[:votable_type].to_s.capitalize.constantize.find(params[:votable_id])
|
109
|
+
end
|
110
|
+
|
111
|
+
def voted(uservotes)
|
112
|
+
if params[:action] == "like"
|
113
|
+
uservotes.first.delete
|
114
|
+
render(json: { status: :ok, message: "unliked successfully." })
|
115
|
+
else
|
116
|
+
render(json: { status: :ok, message: "you already #{params[:action]}voted." })
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def send_get_response(upvotes,downvotes)
|
121
|
+
render(json: { status: :ok, upcount: upvotes.size ,upvotes:JSON.parse(upvotes.to_json), downcount: downvotes.size,downvotes: JSON.parse(downvotes.to_json) })
|
122
|
+
end
|
123
|
+
|
124
|
+
def send_post_response(vote)
|
125
|
+
if vote.save
|
126
|
+
if params[:action] == "like"
|
127
|
+
render(json: { status: :ok, message: "liked successfully." })
|
128
|
+
else
|
129
|
+
render(json: { status: :ok, message: "#{params[:action]}voted successfully." })
|
130
|
+
end
|
131
|
+
else
|
132
|
+
render(json: { status: :unprocessable_entity, message: vote.errors })
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def send_like_response(likes)
|
137
|
+
render(json: { status: :ok, likecount: likes.size ,likes:JSON.parse(likes.to_json)})
|
138
|
+
end
|
139
|
+
|
140
|
+
def current_user?
|
141
|
+
return !current_user.blank? ? true : unauthenticated!
|
142
|
+
end
|
143
|
+
|
144
|
+
def unauthenticated!
|
145
|
+
render( json: {status: :unauthorized, errors:"unauthorized access"})
|
146
|
+
end
|
147
|
+
|
148
|
+
def not_found(e)
|
149
|
+
render(json: {status: :not_found, errors: e.message})
|
150
|
+
end
|
151
|
+
|
152
|
+
def vote_params
|
153
|
+
params[:vote].permit(:votable_id, :votable_type)
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
157
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rails_rest_vote"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/config/routes.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Rails.application.routes.draw do
|
2
|
+
#namespace :rails_rest_vote do
|
3
|
+
#namespace :api do
|
4
|
+
post 'api/votes/up' => 'rails_rest_vote/api/votes#up' #API for voting up
|
5
|
+
post 'api/votes/down' => 'rails_rest_vote/api/votes#down' #API for voting down
|
6
|
+
post 'api/likes' => 'rails_rest_vote/api/votes#like' #API for like unlike feature
|
7
|
+
get 'api/votes/user' => 'rails_rest_vote/api/votes#user_vote_count' #API for vote count done by a particular user
|
8
|
+
get 'api/votes/model' => 'rails_rest_vote/api/votes#model_vote_count' #API for vote count done on particular model
|
9
|
+
get 'api/likes/user' => 'rails_rest_vote/api/votes#user_like_count' #API for like count done by a particular user
|
10
|
+
get 'api/likes/model' => 'rails_rest_vote/api/votes#model_like_count' #API for like count done on particular model
|
11
|
+
#end
|
12
|
+
#end
|
13
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# Requires
|
2
|
+
require 'rails/generators'
|
3
|
+
require 'rails/generators/active_record'
|
4
|
+
require 'rails/generators/migration'
|
5
|
+
|
6
|
+
class RailsRestVoteGenerator < Rails::Generators::NamedBase
|
7
|
+
include Rails::Generators::Migration
|
8
|
+
def self.source_root
|
9
|
+
@source_root ||= File.join(File.dirname(__FILE__), 'templates')
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.next_migration_number(dirname)
|
13
|
+
if ActiveRecord::Base.timestamped_migrations
|
14
|
+
Time.new.utc.strftime("%Y%m%d%H%M%S")
|
15
|
+
else
|
16
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
#copy vote migration file to host application from template folder.
|
21
|
+
def create_migration_file
|
22
|
+
migration_template 'migration.rb', 'db/migrate/create_votes.rb'
|
23
|
+
end
|
24
|
+
|
25
|
+
#create vote model to host application
|
26
|
+
def create_model_file
|
27
|
+
create_file 'app/models/vote.rb',vote_model
|
28
|
+
end
|
29
|
+
|
30
|
+
#inject association in user.rb model of host application
|
31
|
+
#
|
32
|
+
#has_many :votes
|
33
|
+
#
|
34
|
+
def inject_model_content
|
35
|
+
content = model_contents
|
36
|
+
|
37
|
+
class_path = if namespaced?
|
38
|
+
class_name.to_s.split("::")
|
39
|
+
else
|
40
|
+
[class_name]
|
41
|
+
end
|
42
|
+
|
43
|
+
indent_depth = class_path.size - 1
|
44
|
+
content = content.split("\n").map { |line| " " * indent_depth + line } .join("\n") << "\n"
|
45
|
+
|
46
|
+
inject_into_class(model_path, class_path.last, content) if model_exists?
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def model_contents
|
52
|
+
buffer = <<-CONTENT
|
53
|
+
has_many :votes
|
54
|
+
CONTENT
|
55
|
+
buffer
|
56
|
+
end
|
57
|
+
|
58
|
+
def vote_model
|
59
|
+
<<RUBY
|
60
|
+
class Vote < ActiveRecord::Base
|
61
|
+
belongs_to :#{singular_table_name}
|
62
|
+
belongs_to :votable, :polymorphic =>true
|
63
|
+
validates :votable_type, :votable_id, :presence => true
|
64
|
+
end
|
65
|
+
RUBY
|
66
|
+
end
|
67
|
+
|
68
|
+
def model_exists?
|
69
|
+
File.exists?(File.join(destination_root, model_path))
|
70
|
+
end
|
71
|
+
|
72
|
+
def model_path
|
73
|
+
@model_path ||= File.join("app", "models", "#{file_path}.rb")
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class CreateVotes < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :votes do |t|
|
4
|
+
t.boolean :vote #only for up down vote usage, not for like unlike feature.
|
5
|
+
t.references :votable, :polymorphic => true
|
6
|
+
t.timestamps null: false
|
7
|
+
end
|
8
|
+
|
9
|
+
#user table reference added.
|
10
|
+
add_reference :votes, :<%=singular_table_name%>, index: true, foreign_key: true
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# Requires
|
2
|
+
require "rails_rest_vote/version"
|
3
|
+
require "active_support/dependencies"
|
4
|
+
|
5
|
+
module RailsRestVote
|
6
|
+
|
7
|
+
# Our host application root path
|
8
|
+
# We set this when the engine is initialized
|
9
|
+
mattr_accessor :app_root
|
10
|
+
|
11
|
+
# Yield self on setup for nice config blocks
|
12
|
+
def self.setup
|
13
|
+
yield self
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Require our engine
|
18
|
+
require "rails_rest_vote/engine"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module RailsRestVote
|
2
|
+
class Engine < Rails::Engine
|
3
|
+
initialize "rails_rest_vote.load_app_instance_data" do |app|
|
4
|
+
RailsRestVote.setup do |config|
|
5
|
+
config.app_root = app.root
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
initialize "rails_rest_vote.load_static_assets" do |app|
|
10
|
+
app.middleware.use ::ActionDispatch::Static, "#{root}/public"
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rails_rest_vote/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rails_rest_vote"
|
8
|
+
spec.version = RailsRestVote::VERSION
|
9
|
+
spec.authors = ["satendra02"]
|
10
|
+
spec.email = ["satendrarai5@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Add voting ability to rails models.}
|
13
|
+
spec.description = %q{RestFul voting gem for your rails app.}
|
14
|
+
spec.homepage = "https://github.com/tixdo/rails_rest_vote"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency 'rails', '~> 4.2', '>= 4.2.5'
|
25
|
+
spec.add_runtime_dependency 'json', '~> 1.8', '>= 1.8.3'
|
26
|
+
spec.add_dependency "orm_adapter", "~> 0.1"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_rest_vote
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- satendra02
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.2'
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 4.2.5
|
51
|
+
type: :development
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '4.2'
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 4.2.5
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: json
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '1.8'
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 1.8.3
|
71
|
+
type: :runtime
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - "~>"
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '1.8'
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 1.8.3
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: orm_adapter
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - "~>"
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0.1'
|
88
|
+
type: :runtime
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - "~>"
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0.1'
|
95
|
+
description: RestFul voting gem for your rails app.
|
96
|
+
email:
|
97
|
+
- satendrarai5@gmail.com
|
98
|
+
executables: []
|
99
|
+
extensions: []
|
100
|
+
extra_rdoc_files: []
|
101
|
+
files:
|
102
|
+
- ".gitignore"
|
103
|
+
- CODE_OF_CONDUCT.md
|
104
|
+
- Gemfile
|
105
|
+
- LICENSE.txt
|
106
|
+
- README.md
|
107
|
+
- Rakefile
|
108
|
+
- app/controllers/rails_rest_vote/api/votes_controller.rb
|
109
|
+
- bin/console
|
110
|
+
- bin/setup
|
111
|
+
- config/routes.rb
|
112
|
+
- lib/generators/rails_rest_vote/rails_rest_vote_generator.rb
|
113
|
+
- lib/generators/rails_rest_vote/templates/migration.rb
|
114
|
+
- lib/rails_rest_vote.rb
|
115
|
+
- lib/rails_rest_vote/engine.rb
|
116
|
+
- lib/rails_rest_vote/version.rb
|
117
|
+
- rails_rest_vote.gemspec
|
118
|
+
homepage: https://github.com/tixdo/rails_rest_vote
|
119
|
+
licenses:
|
120
|
+
- MIT
|
121
|
+
metadata: {}
|
122
|
+
post_install_message:
|
123
|
+
rdoc_options: []
|
124
|
+
require_paths:
|
125
|
+
- lib
|
126
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
requirements: []
|
137
|
+
rubyforge_project:
|
138
|
+
rubygems_version: 2.4.6
|
139
|
+
signing_key:
|
140
|
+
specification_version: 4
|
141
|
+
summary: Add voting ability to rails models.
|
142
|
+
test_files: []
|