demarches-normaliennes/app/models/concerns/dossier_prefillable_concern.rb

17 lines
515 B
Ruby
Raw Normal View History

2022-11-28 15:54:14 +01:00
# frozen_string_literal: true
module DossierPrefillableConcern
2022-11-28 15:54:14 +01:00
extend ActiveSupport::Concern
def prefill!(champs_attributes, identity_attributes)
return if champs_attributes.empty? && identity_attributes.empty?
attributes = { prefilled: true }
attributes[:champs_attributes] = champs_attributes.map { |h| h.merge(prefilled: true) }
attributes[:individual_attributes] = identity_attributes if identity_attributes.present?
2022-11-28 15:54:14 +01:00
assign_attributes(attributes)
2022-11-28 15:54:14 +01:00
save(validate: false)
end
end