flat_keys.rb 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. class Sequencer
  3. class Unit
  4. module Import
  5. module Common
  6. module Mapping
  7. class FlatKeys < Sequencer::Unit::Base
  8. include ::Sequencer::Unit::Import::Common::Mapping::Mixin::ProvideMapped
  9. prepend ::Sequencer::Unit::Import::Common::Model::Mixin::Skip::Action
  10. skip_any_action
  11. uses :resource
  12. provides :mapped
  13. def process
  14. provide_mapped do
  15. mapped
  16. end
  17. end
  18. private
  19. def mapped
  20. @mapped ||= begin
  21. resource_with_indifferent_access = resource.with_indifferent_access
  22. mapping.symbolize_keys.to_h do |source, local|
  23. [local, resource_with_indifferent_access[source]]
  24. end.with_indifferent_access
  25. end
  26. end
  27. def mapping
  28. raise "Missing implementation of '#{__method__}' method for '#{self.class.name}'"
  29. end
  30. end
  31. end
  32. end
  33. end
  34. end
  35. end