Class: CounterCacheUpdate::PolymorphicUpdatorService

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

Instance Method Summary collapse

Constructor Details

#initialize(reflection:) ⇒ PolymorphicUpdatorService



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

def initialize(reflection:)
  @class = reflection.active_record
  @reflection = reflection
end

Instance Method Details

#performObject



7
8
9
10
11
12
13
# File 'app/services/counter_cache_update/polymorphic_updator_service.rb', line 7

def perform
  foreign_types.each do |foreign_type|
    CounterCacheUpdate::TableUpdatorService.execute!(reflection: @reflection, model_class: foreign_type.constantize)
  end

  succeed!
end