Class: Counter::Value

Inherits:
ApplicationRecord
  • Object
show all
Includes:
Calculated, Conditional, Definable, Hooks, Increment, Recalculatable, Reset, Summable, Verifyable
Defined in:
app/models/counter/value.rb

Overview

Schema Information

Table name: counter_values

id          :integer          not null, primary key
type        :string           indexed
name        :string           indexed
value       :integer          default(0)
parent_type :string           indexed => [parent_id]
parent_id   :integer          indexed => [parent_type]
created_at  :datetime         not null
updated_at  :datetime         not null

Class Method Summary collapse

Methods included from Verifyable

#correct!, #correct?, #verify

Methods included from Recalculatable

#count_by_sql, #recalc!, #recalc_scope, #sum_by_sql

Class Method Details

.find_counter(counter) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/models/counter/value.rb', line 23

def self.find_counter counter
  counter_name = if counter.is_a?(String) || counter.is_a?(Symbol)
    counter.to_s
  elsif counter.is_a?(Class) && counter.ancestors.include?(Counter::Definition)
    definition = counter.instance
    raise "Unable to find counter #{definition.name} via Counter::Value.find_counter. Use must use #{definition.model}#find_counter}" unless definition.global?

    counter.instance.record_name
  else
    counter.to_s
  end

  find_or_initialize_by name: counter_name
end

.table_name_prefixObject



15
16
17
# File 'app/models/counter/value.rb', line 15

def self.table_name_prefix
  "counter_"
end