Class: Promethee::TableUpgradeService

Inherits:
Object
  • Object
show all
Defined in:
app/services/promethee/table_upgrade_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model_name) ⇒ TableUpgradeService

Returns a new instance of TableUpgradeService.



5
6
7
8
9
10
11
12
13
14
# File 'app/services/promethee/table_upgrade_service.rb', line 5

def initialize(model_name)
  begin
    model_class = model_name.constantize
    objects = model_class.all.select { |page| page.data&.to_json&.include? '"type":"table"' }
  rescue
    puts 'Please provide a valid model name (e.g. `rake promethee:upgrade_table[Page]`)'
    exit
  end
  @objects = objects
end

Instance Attribute Details

#objectsObject

Returns the value of attribute objects.



3
4
5
# File 'app/services/promethee/table_upgrade_service.rb', line 3

def objects
  @objects
end

Instance Method Details

#startObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/services/promethee/table_upgrade_service.rb', line 16

def start
  puts '= START TABLE UPGRADE ='
  puts "Number of objects: #{objects.count}"
  objects.each do |object|
    puts "Processing object ##{object.id}"

    object.data = process_component(object.data)
    object.save
    puts "End processing object ##{object.id}"
  end
  puts '====== END UPGRADER ========'
end