Module: PeteOnRails::Acts::Voter::InstanceMethods
- Defined in:
- lib/acts_as_voter.rb
Overview
This module contains instance methods
Instance Method Summary collapse
- #vote(voteable, vote) ⇒ Object
- #vote_against(voteable) ⇒ Object
-
#vote_count(for_or_against = "all") ⇒ Object
Usage user.vote_count(true) # All +1 votes user.vote_count(false) # All -1 votes user.vote_count() # All votes.
- #vote_for(voteable) ⇒ Object
- #voted_against?(voteable) ⇒ Boolean
- #voted_for?(voteable) ⇒ Boolean
- #voted_on?(voteable) ⇒ Boolean
Instance Method Details
#vote(voteable, vote) ⇒ Object
54 55 56 57 58 |
# File 'lib/acts_as_voter.rb', line 54 def vote(voteable, vote) Vote.create(:vote => vote, :voteable => voteable, :voter => self).tap do |v| voteable.reload_vote_counter if !v.new_record? and voteable.respond_to?(:reload_vote_counter) end.errors.empty? end |
#vote_against(voteable) ⇒ Object
50 51 52 |
# File 'lib/acts_as_voter.rb', line 50 def vote_against(voteable) self.vote(voteable, -1) end |
#vote_count(for_or_against = "all") ⇒ Object
Usage user.vote_count(true) # All +1 votes
user.vote_count(false) # All -1 votes
user.vote_count() # All votes
29 30 31 32 |
# File 'lib/acts_as_voter.rb', line 29 def vote_count(for_or_against = "all") return self.votes.size if for_or_against == "all" self.votes.count(:conditions => {:vote => (for_or_against ? 1 : -1)}) end |
#vote_for(voteable) ⇒ Object
46 47 48 |
# File 'lib/acts_as_voter.rb', line 46 def vote_for(voteable) self.vote(voteable, 1) end |
#voted_against?(voteable) ⇒ Boolean
38 39 40 |
# File 'lib/acts_as_voter.rb', line 38 def voted_against?(voteable) voteable.voted_by?(self, false) end |
#voted_for?(voteable) ⇒ Boolean
34 35 36 |
# File 'lib/acts_as_voter.rb', line 34 def voted_for?(voteable) voteable.voted_by?(self, true) end |
#voted_on?(voteable) ⇒ Boolean
42 43 44 |
# File 'lib/acts_as_voter.rb', line 42 def voted_on?(voteable) voteable.voted_by?(self) end |