Module: Juixe::Acts::Voteable::VoteCounterClassMethods

Defined in:
lib/acts_as_voteable.rb

Overview

This module contains class methods Vote class

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



44
45
46
47
48
# File 'lib/acts_as_voteable.rb', line 44

def self.included(base)
  base.class_inheritable_array(:vote_counters)
  base.after_create { |record| record.update_vote_counters(1) }
  base.before_destroy { |record| record.update_vote_counters(-1) }
end

Instance Method Details

#update_vote_counters(direction) ⇒ Object



50
51
52
53
# File 'lib/acts_as_voteable.rb', line 50

def update_vote_counters direction
  klass, vtbl = self.voteable.class, self.voteable
  klass.update_counters(vtbl.id, vtbl.vote_counter_column.to_sym => (self.vote * direction) ) if self.vote_counters.any?{|c| c == klass} 
end