Module: Tally::Countable

Extended by:
ActiveSupport::Concern
Defined in:
lib/tally/countable.rb

Overview

An ActiveSupport::Concern mixin for Rails models that want to increment counters for a specific model record.

Instance Method Summary collapse

Instance Method Details

#increment_tally(key, by = 1) ⇒ Object



10
11
12
13
14
# File 'lib/tally/countable.rb', line 10

def increment_tally(key, by = 1)
  return if new_record?

  Tally.increment(key, self, by)
end

#tally_records(search_params = {}) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/tally/countable.rb', line 16

def tally_records(search_params = {})
  if search_params.present?
    RecordSearcher.search(search_params.merge(record: self))
  else
    Record.where(recordable: self)
  end
end