Class: CounterCacheUpdate::TableUpdatorService

Inherits:
ServicePattern::Service
  • Object
show all
Defined in:
app/services/counter_cache_update/table_updator_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reflection:, model_class: nil) ⇒ TableUpdatorService

Returns a new instance of TableUpdatorService.



4
5
6
7
8
9
# File 'app/services/counter_cache_update/table_updator_service.rb', line 4

def initialize(reflection:, model_class: nil)
  @reflection = reflection

  @model_class = model_class
  @model_class ||= @reflection.class_name.constantize
end

Instance Attribute Details

#model_classObject (readonly)

Returns the value of attribute model_class.



2
3
4
# File 'app/services/counter_cache_update/table_updator_service.rb', line 2

def model_class
  @model_class
end

#reflectionObject (readonly)

Returns the value of attribute reflection.



2
3
4
# File 'app/services/counter_cache_update/table_updator_service.rb', line 2

def reflection
  @reflection
end

Instance Method Details

#performObject



11
12
13
14
# File 'app/services/counter_cache_update/table_updator_service.rb', line 11

def perform
  model_class.connection.execute(sql)
  succeed!
end