2021-12-16 09:49:49 +01:00
|
|
|
namespace :zones do
|
|
|
|
task populate_zones: :environment do
|
|
|
|
puts "Running deploy task 'populate_zones'"
|
2021-12-14 14:33:19 +01:00
|
|
|
|
2022-08-12 17:19:42 +02:00
|
|
|
collectivite = Zone.find_or_create_by!(acronym: 'COLLECTIVITE')
|
|
|
|
coll_label = collectivite.labels.find_or_initialize_by(designated_on: Date.parse('1977-07-30'))
|
|
|
|
coll_label.update(name: 'Collectivité territoriale')
|
|
|
|
|
2021-12-16 09:49:49 +01:00
|
|
|
config = Psych.safe_load(File.read(Rails.root.join("config", "zones.yml")))
|
|
|
|
config["ministeres"].each do |ministere|
|
|
|
|
acronym = ministere.keys.first
|
2022-08-12 17:19:42 +02:00
|
|
|
zone = Zone.find_or_create_by!(acronym: acronym)
|
|
|
|
labels_a = ministere[acronym]
|
|
|
|
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
|
2021-12-16 09:49:49 +01:00
|
|
|
end
|
2021-12-14 14:33:19 +01:00
|
|
|
end
|
|
|
|
end
|