mongoid_vote 0.0.1.2 → 0.0.1.3

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.
@@ -1,3 +1,3 @@
1
1
  module MongoidVote
2
- VERSION = "0.0.1.2"
2
+ VERSION = "0.0.1.3"
3
3
  end
@@ -44,8 +44,6 @@ module MongoidVote
44
44
  self.votes["down"]
45
45
  end
46
46
 
47
- private
48
-
49
47
  def current_vote(user)
50
48
  if self.votes["up"].include? user.id.to_s
51
49
  :up
@@ -54,23 +52,25 @@ module MongoidVote
54
52
  end
55
53
  end
56
54
 
57
- def vote_adjust(current_vote, vote, user)
58
- unless current_vote.to_s == vote
59
- if !current_vote && vote == "up"
55
+ private
56
+
57
+ def vote_adjust(current, vote, user)
58
+ unless current.to_s == vote
59
+ if !current && vote == "up"
60
60
  self.votes["up_count"] += 1
61
61
  self.votes["count"] += 1
62
62
  self.votes["up"] << user.id.to_s
63
- elsif !current_vote && vote == "down"
63
+ elsif !current && vote == "down"
64
64
  self.votes["down_count"] -= 1
65
65
  self.votes["count"] -= 1
66
66
  self.votes["down"] << user.id.to_s
67
- elsif current_vote == :up && vote == "down"
67
+ elsif current == :up && vote == "down"
68
68
  self.votes["up_count"] -= 1
69
69
  self.votes["down_count"] -= 1
70
70
  self.votes["count"] -= 2
71
71
  self.votes["up"].delete_if {|x| x == user.id.to_s}
72
72
  self.votes["down"] << user.id.to_s
73
- elsif current_vote == :down && vote == "up"
73
+ elsif current == :down && vote == "up"
74
74
  self.votes["down_count"] += 1
75
75
  self.votes["up_count"] += 1
76
76
  self.votes["count"] += 2
data/readme.rdoc CHANGED
@@ -1,16 +1,22 @@
1
1
  = Mongoid-Vote
2
2
 
3
- A basic gem that adds voting capabilities to a Mongoid document or embedded document.
3
+ A basic gem that adds voting capabilities to a Mongoid document. Will work on embedded documents.
4
4
 
5
5
  == Installation
6
6
 
7
7
  === Rails 3.x
8
8
 
9
- To install the gem, add this to your Gemfile
9
+ To install the gem, add this to your Gemfile:
10
10
 
11
11
  gem 'mongoid_vote'
12
12
 
13
- run "bundle install"
13
+ Run:
14
+
15
+ bundle install
16
+
17
+ Then add this to the document model you'd like to add voting capabilites to:
18
+
19
+ include MongoidVote::Voteable
14
20
 
15
21
  == Usage Examples
16
22
 
@@ -25,6 +31,8 @@ run "bundle install"
25
31
  @comment.upvoters # up voters
26
32
  @comment.downvoters # down voters
27
33
 
34
+ @comment.current_vote(@user) # returns :up / :down / nil
35
+
28
36
  == Notes
29
37
 
30
- Currently only one vote is allowed per object (i.e. an up vote will replace a previous down vote if one existed).
38
+ Currently only one vote is allowed per object per user (i.e. an up vote by a user will replace a previous down vote if one existed).
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_vote
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.2
4
+ version: 0.0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-03 00:00:00.000000000 Z
12
+ date: 2011-12-04 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A basic Mongoid voting gem which allows voting on embedded documents.
15
15
  email: