custom_fields.rb 967 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Sequencer::Unit::Import::Zendesk::Common::CustomFields < Sequencer::Unit::Base
  3. include ::Sequencer::Unit::Import::Common::Mapping::Mixin::ProvideMapped
  4. uses :resource, :field_map, :model_class
  5. def process
  6. provide_mapped do
  7. attributes_hash
  8. end
  9. end
  10. private
  11. def remote_fields
  12. raise 'Missing implementation of remote_fields method'
  13. end
  14. def fields
  15. @fields ||= remote_fields
  16. end
  17. def attributes_hash
  18. return {} if fields.blank?
  19. fields.each_with_object({}) do |(key, value), result|
  20. next if value.nil?
  21. if custom_fields_map.nil?
  22. result[key] = value
  23. else
  24. local_name = custom_fields_map[key]
  25. result[ local_name.to_sym ] = value
  26. end
  27. end
  28. end
  29. def custom_fields_map
  30. @custom_fields_map ||= begin
  31. if model_class
  32. field_map[model_class.name]
  33. end
  34. end
  35. end
  36. end