Class: CounterCacheUpdate::UpdateService

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(use_progress_bar: false) ⇒ UpdateService

Returns a new instance of UpdateService.



4
5
6
# File 'app/services/counter_cache_update/update_service.rb', line 4

def initialize(use_progress_bar: false)
  @use_progress_bar = use_progress_bar
end

Instance Attribute Details

#use_progress_barObject (readonly)

Returns the value of attribute use_progress_bar.



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

def use_progress_bar
  @use_progress_bar
end

Instance Method Details

#execute!Object



8
9
10
11
12
13
14
15
16
17
18
# File 'app/services/counter_cache_update/update_service.rb', line 8

def execute!
  Rails.application.eager_load!

  if use_progress_bar
    require "progress_bar"
    @progress_bar = ProgressBar.new(model_classes.size)
  end

  update_relationships!
  ServicePattern::Response.new(success: true)
end