Module: Juixe::Acts::Voteable::InstanceMethods
- Defined in:
- lib/acts_as_voteable.rb
Overview
This module contains instance methods
Instance Method Summary collapse
- #voted_by?(voter, for_or_against = "all") ⇒ Boolean
- #voters_who_voted ⇒ Object
- #votes_against ⇒ Object
-
#votes_count ⇒ Object
Same as voteable.votes.size.
- #votes_for ⇒ Object
- #votes_total ⇒ Object
Instance Method Details
#voted_by?(voter, for_or_against = "all") ⇒ Boolean
150 151 152 153 |
# File 'lib/acts_as_voteable.rb', line 150 def voted_by?(voter, for_or_against = "all") = (for_or_against == "all") ? {} : {:vote => (for_or_against ? 1 : -1)} self.votes.exists?({:voter_id => voter.id, :voter_type => voter.class.name}.merge()) end |
#voters_who_voted ⇒ Object
146 147 148 |
# File 'lib/acts_as_voteable.rb', line 146 def voters_who_voted self.votes.collect(&:voter) end |
#votes_against ⇒ Object
133 134 135 |
# File 'lib/acts_as_voteable.rb', line 133 def votes_against self.votes.count(:conditions => {:vote => -1}) end |
#votes_count ⇒ Object
Same as voteable.votes.size
138 139 140 |
# File 'lib/acts_as_voteable.rb', line 138 def votes_count self.votes.size end |
#votes_for ⇒ Object
129 130 131 |
# File 'lib/acts_as_voteable.rb', line 129 def votes_for self.votes.count(:conditions => {:vote => 1}) end |
#votes_total ⇒ Object
142 143 144 |
# File 'lib/acts_as_voteable.rb', line 142 def votes_total respond_to?(:vote_counter_column) ? send(self.vote_counter_column) : self.votes.sum(:vote) end |