module Tadpoll::Voter
Public Class Methods
included(base)
click to toggle source
# File lib/tadpoll/voter.rb, line 4 def self.included(base) base.class_eval do has_many :votes, :class_name => 'Tadpoll::Vote', :as => :voter, :dependent => :destroy end end
Public Instance Methods
unvote_for_option(option)
click to toggle source
Unvote for an option
# File lib/tadpoll/voter.rb, line 16 def unvote_for_option(option) option.unvote(self) end
unvote_for_poll(poll)
click to toggle source
Unvote for a poll
# File lib/tadpoll/voter.rb, line 21 def unvote_for_poll(poll) poll.unvote(self) end
vote_for(option)
click to toggle source
Vote
for an option
# File lib/tadpoll/voter.rb, line 11 def vote_for(option) option.vote(self) end
voted_on?(args = {})
click to toggle source
T / F votes for given params
# File lib/tadpoll/voter.rb, line 26 def voted_on?(args = {}) votes.where(args).count > 0 end
voted_on_option?(option)
click to toggle source
T / F Voter
voted for given option
# File lib/tadpoll/voter.rb, line 36 def voted_on_option?(option) voted_on?({poll_id: option.poll_id, option_id: option.id}) end
voted_on_poll?(poll)
click to toggle source
T / F Voter
voted on given poll
# File lib/tadpoll/voter.rb, line 31 def voted_on_poll?(poll) voted_on?({poll_id: poll.id}) end