Module: Mongoid::Voteable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/mongoid/voteable.rb
Constant Summary
- VOTE_POINT =
How many points should be assigned for each up or down vote. This hash should be accessed and manipulated using Voteable.vote_point method
{}
Instance Method Summary (collapse)
-
- (Object) down_voter_ids
Array of down voter ids.
-
- (Object) down_votes_count
Get the number of down votes.
-
- (Object) up_voter_ids
Array of up voter ids.
-
- (Object) up_votes_count
Get the number of up votes.
-
- (Object) vote(options)
Make a vote on this votee.
-
- (Object) vote_value(voter)
Get a voted value on this votee.
-
- (Object) votes_count
Get the number of votes count.
-
- (Object) votes_point
Get the votes point.
Instance Method Details
- (Object) down_voter_ids
Array of down voter ids
222 223 224 |
# File 'lib/mongoid/voteable.rb', line 222 def down_voter_ids voteable.try(:[], 'down_voter_ids') || [] end |
- (Object) down_votes_count
Get the number of down votes
202 203 204 |
# File 'lib/mongoid/voteable.rb', line 202 def down_votes_count down_voter_ids.length end |
- (Object) up_voter_ids
Array of up voter ids
217 218 219 |
# File 'lib/mongoid/voteable.rb', line 217 def up_voter_ids voteable.try(:[], 'up_voter_ids') || [] end |
- (Object) up_votes_count
Get the number of up votes
197 198 199 |
# File 'lib/mongoid/voteable.rb', line 197 def up_votes_count up_voter_ids.length end |
- (Object) vote(options)
Make a vote on this votee
174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/mongoid/voteable.rb', line 174 def vote() [:votee_id] ||= _id [:votee] ||= self if [:unvote] [:value] ||= vote_value([:voter_id]) else [:revote] ||= !vote_value([:voter_id]).nil? end self.class.vote() end |
- (Object) vote_value(voter)
Get a voted value on this votee
190 191 192 193 194 |
# File 'lib/mongoid/voteable.rb', line 190 def vote_value(voter) voter_id = voter.is_a?(BSON::ObjectId) ? voter : voter._id return :up if up_voter_ids.include?(voter_id) return :down if down_voter_ids.include?(voter_id) end |
- (Object) votes_count
Get the number of votes count
207 208 209 |
# File 'lib/mongoid/voteable.rb', line 207 def votes_count voteable.try(:[], 'votes_count') || 0 end |
- (Object) votes_point
Get the votes point
212 213 214 |
# File 'lib/mongoid/voteable.rb', line 212 def votes_point voteable.try(:[], 'votes_point') || 0 end |