Class: AwesomeCounterCache::CounterCache
- Inherits:
-
Object
- Object
- AwesomeCounterCache::CounterCache
- Defined in:
- lib/awesome_counter_cache/counter_cache.rb
Instance Attribute Summary collapse
-
#column_name ⇒ Object
readonly
Returns the value of attribute column_name.
-
#delta_magnitude ⇒ Object
readonly
Returns the value of attribute delta_magnitude.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#model_class ⇒ Object
readonly
Returns the value of attribute model_class.
-
#relation_name ⇒ Object
readonly
Returns the value of attribute relation_name.
Instance Method Summary collapse
-
#initialize(column_name:, delta_magnitude:, id:, model_class:, relation_name:) ⇒ CounterCache
constructor
A new instance of CounterCache.
- #reflection ⇒ Object
- #relation_foreign_key ⇒ Object
Constructor Details
#initialize(column_name:, delta_magnitude:, id:, model_class:, relation_name:) ⇒ CounterCache
Returns a new instance of CounterCache.
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/awesome_counter_cache/counter_cache.rb', line 4 def initialize(column_name:, delta_magnitude:, id:, model_class:, relation_name:) @column_name = column_name @delta_magnitude = delta_magnitude @id = id @model_class = model_class @relation_name = relation_name raise "Invalid model class: #{model_class&.name}" if model_class.blank? raise "Invalid relation name: #{relation_name}" if relation_name.blank? end |
Instance Attribute Details
#column_name ⇒ Object (readonly)
Returns the value of attribute column_name.
2 3 4 |
# File 'lib/awesome_counter_cache/counter_cache.rb', line 2 def column_name @column_name end |
#delta_magnitude ⇒ Object (readonly)
Returns the value of attribute delta_magnitude.
2 3 4 |
# File 'lib/awesome_counter_cache/counter_cache.rb', line 2 def delta_magnitude @delta_magnitude end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
2 3 4 |
# File 'lib/awesome_counter_cache/counter_cache.rb', line 2 def id @id end |
#model_class ⇒ Object (readonly)
Returns the value of attribute model_class.
2 3 4 |
# File 'lib/awesome_counter_cache/counter_cache.rb', line 2 def model_class @model_class end |
#relation_name ⇒ Object (readonly)
Returns the value of attribute relation_name.
2 3 4 |
# File 'lib/awesome_counter_cache/counter_cache.rb', line 2 def relation_name @relation_name end |
Instance Method Details
#reflection ⇒ Object
15 16 17 |
# File 'lib/awesome_counter_cache/counter_cache.rb', line 15 def reflection model_class.reflections.fetch(relation_name.to_s) end |
#relation_foreign_key ⇒ Object
19 20 21 |
# File 'lib/awesome_counter_cache/counter_cache.rb', line 19 def relation_foreign_key reflection.foreign_key end |