Module: Tadpoll::Voter
- Defined in:
- lib/tadpoll/voter.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#unvote_for_option(option) ⇒ Object
Unvote for an option.
-
#unvote_for_poll(poll) ⇒ Object
Unvote for a poll.
-
#vote_for(option) ⇒ Object
Vote for an option.
-
#voted_on?(args = {}) ⇒ Boolean
T / F votes for given params.
-
#voted_on_option?(option) ⇒ Boolean
T / F Voter voted for given option.
-
#voted_on_poll?(poll) ⇒ Boolean
T / F Voter voted on given poll.
Class Method Details
.included(base) ⇒ Object
4 5 6 7 8 |
# 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 |
Instance Method Details
#unvote_for_option(option) ⇒ Object
Unvote for an option
16 17 18 |
# File 'lib/tadpoll/voter.rb', line 16 def unvote_for_option(option) option.unvote(self) end |
#unvote_for_poll(poll) ⇒ Object
Unvote for a poll
21 22 23 |
# File 'lib/tadpoll/voter.rb', line 21 def unvote_for_poll(poll) poll.unvote(self) end |
#vote_for(option) ⇒ Object
Vote for an option
11 12 13 |
# File 'lib/tadpoll/voter.rb', line 11 def vote_for(option) option.vote(self) end |
#voted_on?(args = {}) ⇒ Boolean
T / F votes for given params
26 27 28 |
# File 'lib/tadpoll/voter.rb', line 26 def voted_on?(args = {}) votes.where(args).count > 0 end |
#voted_on_option?(option) ⇒ Boolean
T / F Voter voted for given option
36 37 38 |
# 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) ⇒ Boolean
T / F Voter voted on given poll
31 32 33 |
# File 'lib/tadpoll/voter.rb', line 31 def voted_on_poll?(poll) voted_on?({poll_id: poll.id}) end |