mongoid_vote 0.0.1.1 → 0.0.1.2

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.1"
2
+ VERSION = "0.0.1.2"
3
3
  end
@@ -15,10 +15,37 @@ module MongoidVote
15
15
  end
16
16
 
17
17
  module InstanceMethods
18
- def vote(user, vote = nil)
19
- vote_adjust(self.current_vote(user), vote, user)
18
+
19
+ def upvote(user)
20
+ vote_adjust(current_vote(user), 'up', user)
21
+ end
22
+
23
+ def downvote(user)
24
+ vote_adjust(current_vote(user), 'down', user)
25
+ end
26
+
27
+ def votecount
28
+ self.votes["count"]
20
29
  end
21
30
 
31
+ def downcount
32
+ self.votes["down_count"]
33
+ end
34
+
35
+ def upcount
36
+ self.votes["up_count"]
37
+ end
38
+
39
+ def upvoters
40
+ self.votes["up"]
41
+ end
42
+
43
+ def downvoters
44
+ self.votes["down"]
45
+ end
46
+
47
+ private
48
+
22
49
  def current_vote(user)
23
50
  if self.votes["up"].include? user.id.to_s
24
51
  :up
@@ -27,8 +54,6 @@ module MongoidVote
27
54
  end
28
55
  end
29
56
 
30
- private
31
-
32
57
  def vote_adjust(current_vote, vote, user)
33
58
  unless current_vote.to_s == vote
34
59
  if !current_vote && vote == "up"
@@ -42,13 +67,13 @@ module MongoidVote
42
67
  elsif current_vote == :up && vote == "down"
43
68
  self.votes["up_count"] -= 1
44
69
  self.votes["down_count"] -= 1
45
- self.votes["count"] -= 1
70
+ self.votes["count"] -= 2
46
71
  self.votes["up"].delete_if {|x| x == user.id.to_s}
47
72
  self.votes["down"] << user.id.to_s
48
73
  elsif current_vote == :down && vote == "up"
49
74
  self.votes["down_count"] += 1
50
75
  self.votes["up_count"] += 1
51
- self.votes["count"] += 1
76
+ self.votes["count"] += 2
52
77
  self.votes["down"].delete_if {|x| x == user.id.to_s}
53
78
  self.votes["up"] << user.id.to_s
54
79
  end
data/mongoid_vote.gemspec CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.version = MongoidVote::VERSION
8
8
  s.authors = ["incorvia"]
9
9
  s.email = ["incorvia@gmail.com"]
10
- s.homepage = "http://www.kevinincorvia.com"
10
+ s.homepage = "https://github.com/incorvia/mongoid_vote"
11
11
  s.summary = %q{Mongoid Vote}
12
12
  s.description = %q{A basic Mongoid voting gem which allows voting on embedded documents.}
13
13
 
data/readme.rdoc ADDED
@@ -0,0 +1,30 @@
1
+ = Mongoid-Vote
2
+
3
+ A basic gem that adds voting capabilities to a Mongoid document or embedded document.
4
+
5
+ == Installation
6
+
7
+ === Rails 3.x
8
+
9
+ To install the gem, add this to your Gemfile
10
+
11
+ gem 'mongoid_vote'
12
+
13
+ run "bundle install"
14
+
15
+ == Usage Examples
16
+
17
+
18
+ @comment.upvote(@user) # up vote
19
+ @comment.downvote(@user) # down vote
20
+
21
+ @comment.votecount # vote count
22
+ @comment.upcount # up vote count
23
+ @comment.downcount # down vote count
24
+
25
+ @comment.upvoters # up voters
26
+ @comment.downvoters # down voters
27
+
28
+ == Notes
29
+
30
+ Currently only one vote is allowed per object (i.e. an up vote 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.1
4
+ version: 0.0.1.2
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.000000000Z
12
+ date: 2011-12-03 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:
@@ -26,7 +26,8 @@ files:
26
26
  - lib/mongoid_vote/version.rb
27
27
  - lib/mongoid_vote/voteable.rb
28
28
  - mongoid_vote.gemspec
29
- homepage: http://www.kevinincorvia.com
29
+ - readme.rdoc
30
+ homepage: https://github.com/incorvia/mongoid_vote
30
31
  licenses: []
31
32
  post_install_message:
32
33
  rdoc_options: []