Sha256: 9aa45076101d0a0441dabfcb0691518ca329bcccb9a719cf05e0a758c15dc164
Contents?: true
Size: 1.14 KB
Versions: 1
Compression:
Stored size: 1.14 KB
Contents
module ActsAsVotable module Voter def self.included(base) base.send :include, ActsAsVotable::Voter::InstanceMethods end module ClassMethods end module InstanceMethods def default_conditions { :voter_id => self.id, :voter_type => self.class.name } end def voted_on? votable votes = find_votes(:votable_id => votable.id, :votable_type => votable.class.name) votes.size > 0 end alias :voted_for? :voted_on? def voted_as_when_voting_on votable votes = find_votes(:votable_id => votable.id, :votable_type => votable.class.name) return nil if votes.size == 0 return votes.first.vote_flag end alias :voted_as_when_voting_for :voted_as_when_voting_on def find_votes extra_conditions = {} ActsAsVotable::Vote.find(:all, :conditions => default_conditions.merge(extra_conditions)) end def total_votes_for_class klass find_votes({:votable_type => klass.name}).size end def vote args args[:votable].vote args.merge({:voter => self}) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
acts_as_votable-0.0.5 | lib/acts_as_votable/voter.rb |