Module: ActsAsMeritocracy::ClassMethods

Defined in:
lib/acts_as_meritocracy/model.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_meritocracy(options = {}) ⇒ Object

Example:

class User < ActiveRecord::Base
  acts_as_meritocracy {:min_votes=>, :max_votes=>}}
end


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/acts_as_meritocracy/model.rb', line 13

def acts_as_meritocracy(options={})

  # todo trigger action when decision is reliable
  # acts_as_meritocracy {:quorum=>, :min_consensus=>}}
  #adding class attribute
  #class_attribute :_min_votes, :_max_votes, :_consensus, :_status_update_fct
  #self._min_votes=options[:min_votes] || 3
  #self._max_votes=options[:max_votes] || 6
  #self._consensus=options[:consensus] || 0.7
  #self._status_update_fct=options[:on_status_change] || :decision_updated

  has_many :votes, :as => :voteable, :dependent => :destroy
  has_many :voters, :through => :votes
  attr_accessible :voters, :score, :num_votes, :entropy # entropy


  scope :voted_by, lambda { |user|
    joins(:votes).where("votes.voteable_type = ?", self.name).where("votes.voter_id=?", user.id)
  }

  include ActsAsMeritocracy::InstanceMethods
  extend ActsAsMeritocracy::SingletonMethods
end