Skip to content

Instantly share code, notes, and snippets.

@thedelchop
Created December 2, 2010 00:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thedelchop/724519 to your computer and use it in GitHub Desktop.
Save thedelchop/724519 to your computer and use it in GitHub Desktop.
This is the mixin I want to use
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
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