voteable_mongoid 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mongoid/voteable.rb +6 -4
- metadata +3 -3
data/lib/mongoid/voteable.rb
CHANGED
@@ -19,7 +19,7 @@ module Mongoid
|
|
19
19
|
scope :best_voted, order_by(:votes_point.desc)
|
20
20
|
|
21
21
|
|
22
|
-
def self.vote_point(klass, options = nil)
|
22
|
+
def self.vote_point(klass = self, options = nil)
|
23
23
|
VOTE_POINT[self] ||= {}
|
24
24
|
VOTE_POINT[self][klass] ||= options
|
25
25
|
end
|
@@ -88,7 +88,9 @@ module Mongoid
|
|
88
88
|
VOTE_POINT[self].each do |klass, value_point|
|
89
89
|
next unless association = associations[klass.name.underscore]
|
90
90
|
next unless foreign_key = options[association.options[:foreign_key].to_sym]
|
91
|
-
|
91
|
+
foreign_key = BSON::ObjectID(foreign_key) if foreign_key.is_a?(String)
|
92
|
+
|
93
|
+
klass.collection.update({ :_id => foreign_key }, {
|
92
94
|
'$inc' => options[:revote] ? {
|
93
95
|
:votes_point => ( value == :up ?
|
94
96
|
value_point[:up] - value_point[:down] :
|
@@ -110,8 +112,8 @@ module Mongoid
|
|
110
112
|
options[foreign_key] = read_attribute(foreign_key)
|
111
113
|
end
|
112
114
|
|
113
|
-
options[:votee_id]
|
114
|
-
options[:revote]
|
115
|
+
options[:votee_id] = _id
|
116
|
+
options[:revote] = !vote_value(options[:voter_id]).nil?
|
115
117
|
|
116
118
|
self.class.vote(options)
|
117
119
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: voteable_mongoid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 1
|
10
|
+
version: 0.3.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Alex Nguyen
|