Created
December 2, 2010 00:26
-
-
Save thedelchop/724519 to your computer and use it in GitHub Desktop.
This is the mixin I want to use
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Motion < ActiveRecord::Base | |
validates_inclusion_of :state, :in => | |
%w(waitingsecond waitingexpedited waitingobjection | |
objected voting passed failed approved).push(nil) | |
belongs_to :member | |
has_many :events | |
has_many :motion_conflicts | |
has_many :conflicts, :through => :motion_conflicts | |
include Voting | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Voting | |
#Since its useful to keep track of the votes of members and motions, its preferred to | |
#refactor this methods into a module | |
# @return [ActiveRecord::Relation] All of the votes cast on this motion | |
def votes | |
events.votes | |
end | |
# @return [ActiveRecord::Relation] All of the seconds cast in support of this motion | |
def seconds | |
events.seconds | |
end | |
# @return [Fixnum] Count of current yea votes | |
def yeas | |
votes.yeas.count | |
end | |
alias :ayes :yeas | |
# @return [Fixnum] Count of current nay votes | |
def nays | |
votes.nays.count | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment