voteable_mongoid 0.3.2 → 0.3.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.
- data/lib/mongoid/voteable.rb +16 -5
- metadata +3 -3
data/lib/mongoid/voteable.rb
CHANGED
@@ -41,16 +41,17 @@ module Mongoid
|
|
41
41
|
voter_id = BSON::ObjectID(voter_id) if voter_id.is_a?(String)
|
42
42
|
|
43
43
|
value = value.to_sym
|
44
|
+
value_point = VOTE_POINT[name][name]
|
44
45
|
|
45
46
|
if options[:revote]
|
46
47
|
if value == :up
|
47
48
|
push_field = :up_voter_ids
|
48
49
|
pull_field = :down_voter_ids
|
49
|
-
point_delta =
|
50
|
+
point_delta = value_point[:up] - value_point[:down]
|
50
51
|
else
|
51
52
|
push_field = :down_voter_ids
|
52
53
|
pull_field = :up_voter_ids
|
53
|
-
point_delta = -
|
54
|
+
point_delta = -value_point[:up] + value_point[:down]
|
54
55
|
end
|
55
56
|
|
56
57
|
collection.update({
|
@@ -80,7 +81,7 @@ module Mongoid
|
|
80
81
|
'$push' => { push_field => voter_id },
|
81
82
|
'$inc' => {
|
82
83
|
:votes_count => +1,
|
83
|
-
:votes_point =>
|
84
|
+
:votes_point => value_point[value]
|
84
85
|
}
|
85
86
|
})
|
86
87
|
end
|
@@ -96,7 +97,7 @@ module Mongoid
|
|
96
97
|
value_point[:up] - value_point[:down] :
|
97
98
|
-value_point[:up] + value_point[:down] )
|
98
99
|
} : {
|
99
|
-
:votes_count => 1,
|
100
|
+
:votes_count => value_point[:not_increase_votes_count] ? 0 : 1,
|
100
101
|
:votes_point => value_point[value]
|
101
102
|
}
|
102
103
|
})
|
@@ -118,7 +119,7 @@ module Mongoid
|
|
118
119
|
self.class.vote(options)
|
119
120
|
end
|
120
121
|
|
121
|
-
|
122
|
+
|
122
123
|
def vote_value(x)
|
123
124
|
voter_id = case x
|
124
125
|
when String
|
@@ -133,5 +134,15 @@ module Mongoid
|
|
133
134
|
return :down if down_voter_ids.try(:include?, voter_id)
|
134
135
|
end
|
135
136
|
|
137
|
+
|
138
|
+
def up_votes_count
|
139
|
+
up_voter_ids.length
|
140
|
+
end
|
141
|
+
|
142
|
+
|
143
|
+
def down_votes_count
|
144
|
+
down_voter_ids.length
|
145
|
+
end
|
146
|
+
|
136
147
|
end
|
137
148
|
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: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 3
|
10
|
+
version: 0.3.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Alex Nguyen
|