Module: BallotBox::Base::InstanceMethods

Defined in:
lib/ballot_box/base.rb

Instance Method Summary collapse

Instance Method Details

#ballot_box_cached_columnObject



141
142
143
# File 'lib/ballot_box/base.rb', line 141

def ballot_box_cached_column
  @ballot_box_cached_column ||= self.class.ballot_box_cached_column
end

#ballot_box_place_columnObject



145
146
147
# File 'lib/ballot_box/base.rb', line 145

def ballot_box_place_column
  @ballot_box_place_column ||= self.class.ballot_box_place_column
end

#ballot_box_refresh?Boolean

Returns:

  • (Boolean)


153
154
155
# File 'lib/ballot_box/base.rb', line 153

def ballot_box_refresh?
  self.class.ballot_box_options[:refresh]
end

#ballot_box_update_place!Object



164
165
166
167
168
# File 'lib/ballot_box/base.rb', line 164

def ballot_box_update_place!
  if persisted? && ballot_box_place_column
    self.class.ballot_box_update_place!(self)
  end
end

#ballot_box_update_votes!Object



157
158
159
160
161
162
# File 'lib/ballot_box/base.rb', line 157

def ballot_box_update_votes!
  if persisted? && ballot_box_cached_column
    count = self.votes.select("SUM(value)")
    self.class.update_all("#{ballot_box_cached_column} = (#{count.to_sql})", ["id = ?", id])
  end
end

#ballot_box_valid?(vote) ⇒ Boolean

Returns:

  • (Boolean)


149
150
151
# File 'lib/ballot_box/base.rb', line 149

def ballot_box_valid?(vote)
  self.class.ballot_box_strategies.map { |st| st.new(self, vote) }.map(&:valid?).all?
end