custom_fields.rb 750 B

12345678910111213141516171819202122232425262728293031
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. class Sequencer::Unit::Import::Freshdesk::Mapping::CustomFields < Sequencer::Unit::Base
  3. include ::Sequencer::Unit::Import::Common::Mapping::Mixin::ProvideMapped
  4. uses :resource, :field_map, :model_class
  5. def process
  6. return if !resource['custom_fields']
  7. provide_mapped do
  8. custom_fields
  9. end
  10. end
  11. private
  12. def custom_fields
  13. resource['custom_fields'].each_with_object({}) do |(freshdesk_name, value), result|
  14. local_name = custom_fields_map[freshdesk_name]
  15. next if local_name.blank?
  16. result[ local_name.to_sym ] = value
  17. end
  18. end
  19. def custom_fields_map
  20. @custom_fields_map ||= field_map[model_class.name]
  21. end
  22. end