demarches-normaliennes/app/tasks/maintenance/update_zones_task.rb

29 lines
851 B
Ruby
Raw Normal View History

2024-03-06 19:03:30 +01:00
# frozen_string_literal: true
module Maintenance
class UpdateZonesTask < MaintenanceTasks::Task
# Synchronise les zones en base à partir du fichier de config zones.yml
# 2024-05-27-01 PR #10077
2024-03-06 19:03:30 +01:00
def collection
config = Psych.safe_load(Rails.root.join("config", "zones.yml").read)
config['ministeres']
end
def process(ministere)
acronym = ministere.keys.first
zone = Zone.find_or_create_by!(acronym: acronym)
labels_a = ministere['labels']
labels_a.each do |label_h|
designated_on = label_h.keys.first
label = zone.labels.find_or_initialize_by(designated_on: designated_on)
label.update(name: label_h[designated_on])
end
zone.update(tchap_hs: ministere['tchap_hs']) if ministere['tchap_hs']
end
def count
collection.length
end
end
end