Module: Mongo::Voter
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/voteable_mongo/voter.rb
Instance Method Summary collapse
-
#unvote(options) ⇒ Object
Cancel the vote on a votee.
-
#vote(options, value = nil) ⇒ Object
Vote on a votee.
-
#vote_value(options) ⇒ Symbol?
Get the voted value on a votee.
-
#voted?(options) ⇒ true, false
Check to see if this voter voted on the votee or not.
Instance Method Details
#unvote(options) ⇒ Object
Cancel the vote on a votee
49 50 51 52 53 54 55 56 |
# File 'lib/voteable_mongo/voter.rb', line 49 def unvote() unless .is_a?(Hash) = { :votee => } end [:unvote] = true [:revote] = false vote() end |
#vote(options, value = nil) ⇒ Object
Vote on a votee
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/voteable_mongo/voter.rb', line 62 def vote(, value = nil) if .is_a?(Hash) votee = [:votee] else votee = = { :votee => votee, :value => value } end if votee [:votee_id] = votee.id votee_class = votee.class else votee_class = [:votee_class] end if [:value].nil? [:unvote] = true [:value] = vote_value() else [:revote] = .has_key?(:revote) ? ![:revote].blank? : voted?() end [:voter] = self [:voter_id] = id (votee || votee_class).vote() end |
#vote_value(options) ⇒ Symbol?
Get the voted value on a votee
37 38 39 40 41 42 43 44 |
# File 'lib/voteable_mongo/voter.rb', line 37 def vote_value() votee = unless .is_a?(Hash) else [:votee] || [:votee_class].find([:votee_id]) end votee.vote_value(_id) end |
#voted?(options) ⇒ true, false
Check to see if this voter voted on the votee or not
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/voteable_mongo/voter.rb', line 15 def voted?() unless .is_a?(Hash) votee_class = .class votee_id = .id else votee = [:votee] if votee votee_class = votee.class votee_id = votee.id else votee_class = [:votee_class] votee_id = [:votee_id] end end votee_class.voted?(:voter_id => id, :votee_id => votee_id) end |