voteable_mongoid 0.7.4 → 0.7.5

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.
data/.rvmrc CHANGED
@@ -1,2 +1,2 @@
1
1
  rvm_gemset_create_on_use_flag=1
2
- rvm use 1.9.2@mongoid
2
+ rvm use 1.9.2@voteable
data/CHANGELOG.rdoc CHANGED
@@ -1,13 +1,13 @@
1
1
  == 0.7.4
2
- * Add Voteable#up_voters(VoterClass), Voteable#down_voters(VoterClass), Voteable#voters(VoterClass)
3
- * Add Voter scopes: Voter.up_voted_for(voteable_object), Voter.down_voted_for(voteable_object), Voter.voted_for(voteable_object)
2
+ * Add Votee#up_voters(VoterClass), Votee#down_voters(VoterClass), Votee#voters(VoterClass)
3
+ * Add Voter scopes: Voter.up_voted_for(votee), Voter.down_voted_for(votee), Voter.voted_for(votee)
4
4
  * Add voteable ..., :index => true options
5
5
  * Optimization on unvote and revote validations
6
6
  * Fix for :up & :down points are nil in rake tasks
7
7
 
8
8
  == 0.7.3
9
9
  * Add :return_votee => true option to vote function to warranty always return voteable object
10
- * Add Voteable.voted?, Voteable.up_voted?, Voteable.down_voted?
10
+ * Add Votee.voted?, Votee.up_voted?, Votee.down_voted?
11
11
  * Update parent for ManyToMany relationship
12
12
  * Refactor
13
13
 
@@ -23,7 +23,7 @@
23
23
  * Use readable field names (up, down, up_count, down_count, count, point) instead of very short field names (u, d, uc, dc, c, p)
24
24
 
25
25
  == 0.6.4
26
- * Drop Voter#votees, Voter#up_votees, Voter#down_votees in favor of Voteable#voted_by(voter), Voteable#up_voted_by(voter), Voteable#down_voted_by(voter) scopes
26
+ * Drop Voter#votees, Voter#up_votees, Voter#down_votees in favor of Votee#voted_by(voter), Votee#up_voted_by(voter), Votee#down_voted_by(voter) scopes
27
27
 
28
28
  == 0.6.3
29
29
  * Add rake db:mongoid:voteable:migrate_old_votes to migrate vote data created by version < 0.6.0 to new vote data storage
data/README.rdoc CHANGED
@@ -1,14 +1,17 @@
1
1
  = Voteable Mongoid
2
2
 
3
- Voteable Mongoid allows you to make your Mongoid::Document objects voteable (up or down).
4
- For instance, in a forum, a user can vote up (or down) on a post or a comment.
3
+ Voteable Mongoid allows you to make your Mongoid::Document objects voteable (up or down) and tabulate votes count and votes point for you. For instance, in a forum, a user can vote up (or down) on a post or a comment.
5
4
 
6
- Initial idea is based on http://cookbook.mongodb.org/patterns/votes
7
-
8
- Voteable Mongoid is built for speed. It uses only one database request per collection to validate data, update data, and get updated data.
5
+ Voteable Mongoid is built for speed. It uses only one database request per collection to validate data, update data, and get updated data. Initial idea is based on http://cookbook.mongodb.org/patterns/votes
9
6
 
10
7
  Sample app at https://github.com/vinova/simple_qa
11
8
 
9
+ Benchmarks at https://github.com/vinova/voteable_benchmarks
10
+
11
+ === Sites using voteable_mongoid
12
+ * http://www.amorveneris.com
13
+ * http://zheye.org (https://github.com/huacnlee/quora)
14
+
12
15
  == Installation
13
16
 
14
17
  === Rails 3.0.x
@@ -21,7 +24,7 @@ After that, remember to run "bundle install"
21
24
 
22
25
  == Usage
23
26
 
24
- === Making Post and Comment voteable, User being the voter
27
+ === Make Post and Comment voteable, User become the voter
25
28
 
26
29
  post.rb
27
30
 
@@ -58,7 +61,7 @@ user.rb
58
61
  include Mongoid::Voter
59
62
  end
60
63
 
61
- === Making a vote
64
+ === Make a vote
62
65
 
63
66
  @user.vote(@post, :up)
64
67
 
@@ -89,7 +92,7 @@ Un-vote
89
92
  In-case you need updated voteable object, add :return_votee => true
90
93
  votee = Post.vote(:voter_id => user_id, :votee_id => post_id, :value => :up, :return_votee => true)
91
94
 
92
- === Getting vote_value
95
+ === Get vote_value
93
96
 
94
97
  @user.vote_value(@post)
95
98
  @user.vote_value(:class_type => 'Post', :votee_id => post_id)
@@ -103,14 +106,24 @@ In-case you need updated voteable object, add :return_votee => true
103
106
  @post.voted_by?(@user)
104
107
  @post.voted_by?(user_id)
105
108
 
106
- === Getting votes counts and points
109
+ === Get votes counts and points
107
110
 
108
111
  puts @post.votes_point
109
112
  puts @post.votes_count
110
113
  puts @post.up_votes_count
111
114
  puts @post.down_votes_count
112
115
 
113
- === Getting the list of voted objects of a class
116
+ === Get voters given voted object and voter class
117
+
118
+ @post.up_voters(User)
119
+ @post.down_voters(User)
120
+ @post.voters(User)
121
+ - or -
122
+ User.up_voted_for(@post)
123
+ User.down_voted_for(@post)
124
+ User.voted_for(@post)
125
+
126
+ === Get the list of voted objects of a class
114
127
 
115
128
  Post.voted_by(@user)
116
129
  Post.up_voted_by(@user)
@@ -137,7 +150,6 @@ Ruby
137
150
  Mongoid::Voteable::Tasks.migrate_old_votes
138
151
 
139
152
  == Credits
140
-
141
153
  * Alex Nguyen (alex@vinova.sg) - Author
142
154
  * Stefan Nguyen (stefan@vinova.sg) - Unvoting
143
155
 
@@ -1,3 +1,3 @@
1
1
  module VoteableMongoid
2
- VERSION = '0.7.4'
2
+ VERSION = '0.7.5'
3
3
  end
@@ -42,10 +42,10 @@ module Mongoid
42
42
  # count, point)
43
43
  votes = doc['votes'] || doc['voteable'] || {}
44
44
 
45
- up_voter_ids = votes['u'] || votes['up'] ||
45
+ up_voter_ids = votes['up'] || votes['u'] ||
46
46
  votes['up_voter_ids'] || doc['up_voter_ids'] || []
47
47
 
48
- down_voter_ids = votes['d'] || votes['down'] ||
48
+ down_voter_ids = votes['down'] || votes['d'] ||
49
49
  votes['down_voter_ids'] || doc['down_voter_ids'] || []
50
50
 
51
51
  up_count = up_voter_ids.size
@@ -67,7 +67,13 @@ module Mongoid
67
67
  'down_voter_ids' => true,
68
68
  'votes_count' => true,
69
69
  'votes_point' => true,
70
- 'voteable' => true
70
+ 'voteable' => true,
71
+ 'votes.u' => true,
72
+ 'votes.d' => true,
73
+ 'votes.uc' => true,
74
+ 'votes.dc' => true,
75
+ 'votes.c' => true,
76
+ 'votes.p' => true
71
77
  }
72
78
  }, { :safe => true })
73
79
  end
@@ -99,14 +99,16 @@ module Mongoid
99
99
  # Should run in background since it introduce new index value and
100
100
  # while waiting to build, the system can use _id for voting
101
101
  # http://www.mongodb.org/display/DOCS/Indexing+as+a+Background+Operation
102
- index [['votes.up', 1], ['_id', 1]], :unique => true, :background => true
103
- index [['votes.down', 1], ['_id', 1]], :unique => true, :background => true
102
+ index [['votes.up', ::Mongo::ASCENDING], ['_id', ::Mongo::ASCENDING]],
103
+ :unique => true, :background => true
104
+ index [['votes.down', ::Mongo::ASCENDING], ['_id', ::Mongo::ASCENDING]],
105
+ :unique => true, :background => true
104
106
 
105
107
  # Index counters and point for desc ordering
106
- index [['votes.count', -1]]
107
- index [['votes.up_count', -1]]
108
- index [['votes.down_count', -1]]
109
- index [['votes.point', -1]]
108
+ index [['votes.up_count', ::Mongo::DESCENDING]]
109
+ index [['votes.down_count', ::Mongo::DESCENDING]]
110
+ index [['votes.count', ::Mongo::DESCENDING]]
111
+ index [['votes.point', ::Mongo::DESCENDING]]
110
112
  end
111
113
  end
112
114
  end
data/spec/spec_helper.rb CHANGED
@@ -20,7 +20,6 @@ Mongoid.configure do |config|
20
20
  name = "voteable_mongoid_test"
21
21
  host = "localhost"
22
22
  config.master = Mongo::Connection.new.db(name)
23
- config.embedded_object_id = false
24
23
  end
25
24
 
26
25
 
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.email = ["alex@vinova.sg"]
11
11
  s.homepage = "https://github.com/vinova/voteable_mongoid"
12
12
  s.summary = %q{Add Up / Down Voting for Mongoid}
13
- s.description = %q{Add Up / Down Voting for Mongoid (built for speed by using one Mongodb update-in-place for each collection when provided enough information)}
13
+ s.description = %q{Renamed to voteable_mongo to support both Mongoid and MongoMapper.}
14
14
 
15
15
  s.add_dependency 'mongoid', '~> 2.0.0'
16
16
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: voteable_mongoid
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.7.4
5
+ version: 0.7.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Alex Nguyen
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-02 00:00:00 Z
13
+ date: 2011-05-03 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: mongoid
@@ -45,7 +45,7 @@ dependencies:
45
45
  version: "0"
46
46
  type: :development
47
47
  version_requirements: *id003
48
- description: Add Up / Down Voting for Mongoid (built for speed by using one Mongodb update-in-place for each collection when provided enough information)
48
+ description: Renamed to voteable_mongo to support both Mongoid and MongoMapper.
49
49
  email:
50
50
  - alex@vinova.sg
51
51
  executables: []